Advertisement
infodox

getinfos functions

Jan 24th, 2012
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. # This function gets the MAC address of a specified interface.
  2. def getmac(iface):
  3. data = commands.getoutput("ifconfig " + iface)
  4. words = data.split()
  5. found = 0
  6. for x in words:
  7. #print x
  8. if found != 0:
  9. mac = x
  10. break
  11. if x == "HWaddr":
  12. found = 1
  13. if len(mac) == 0:
  14. mac = 'Mac not found'
  15. mac = mac[:17]
  16. print mac
  17.  
  18. ##### FOR THE ARP SCANNER/SYN SCANNER #####
  19.  
  20. # Function: Get Gateway
  21. def get_default_gateway_linux():
  22. """Read the default gateway directly from /proc."""
  23. with open("/proc/net/route") as fh: # Opens the /proc/net/route interface
  24. for line in fh:
  25. fields = line.strip().split() # splitting shit
  26. if fields[1] != '00000000' or not int(fields[3], 16) & 2: # checking data
  27. continue
  28.  
  29. return socket.inet_ntoa(struct.pack("<L", int(fields[2], 16))) # spits out the gateway!
  30.  
  31. # Function: makerange(), gets gateway, returns the range
  32. def makerange(gwaddr):
  33. SIP=gwaddr.split('.') # Splits the IP address of the gateway
  34. iprange = SIP[0] + '.' + SIP[1] + '.' + SIP[2] + '.0/24' # makes a new one that is the range
  35. return iprange
  36.  
  37. # Defines variable scanrange for scanner
  38. scanrange = makerange(gwaddr)
  39.  
  40. # Faster ARP scanner. outputs list of MAC:IP as per old scanner
  41. print(arping(scanrange))
  42.  
  43. ##### GET MORE SYSTEMINFO #####
  44.  
  45. # Gets meminfo and cpuinfo, outputs to files
  46. getsysteminfo():
  47. os.popen("cat /proc/cpuinfo > /tmp/cpuinfo.txt")
  48. os.popen("cat /proc/meminfo > /tmp/meminfo.txt")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement