Guest User

DiabloHorn

a guest
Jun 25th, 2009
168
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import ctypes
  2. import socket
  3. import struct
  4.  
  5. def get_macaddress(host):
  6.     """
  7.         Borrowed from: http://code.activestate.com/recipes/347812/
  8.         Returns the MAC address of a network host, requires >= WIN2K.
  9.     """
  10.    
  11.     # Check for api availability
  12.     try:
  13.         SendARP = ctypes.windll.Iphlpapi.SendARP
  14.     except:
  15.         raise NotImplementedError('Usage only on Windows 2000 and above')
  16.        
  17.     # Doesn't work with loopbacks, but let's try and help.
  18.     if host == '127.0.0.1' or host.lower() == 'localhost':
  19.         host = socket.gethostname()
  20.    
  21.     # gethostbyname blocks, so use it wisely.
  22.     try:
  23.         inetaddr = ctypes.windll.wsock32.inet_addr(host)
  24.         if inetaddr in (0, -1):
  25.             raise Exception
  26.     except:
  27.         hostip = socket.gethostbyname(host)
  28.         inetaddr = ctypes.windll.wsock32.inet_addr(hostip)
  29.    
  30.     buffer = ctypes.c_buffer(6)
  31.     addlen = ctypes.c_ulong(ctypes.sizeof(buffer))
  32.     if SendARP(inetaddr, 0, ctypes.byref(buffer), ctypes.byref(addlen)) != 0:
  33.         raise WindowsError('Retreival of mac address(%s) - failed' % host)
  34.    
  35.     # Convert binary data into a string.
  36.     macaddr = ''
  37.     for intval in struct.unpack('BBBBBB', buffer):
  38.         if intval > 15:
  39.             replacestr = '0x'
  40.         else:
  41.             replacestr = 'x'
  42.         macaddr = ''.join([macaddr, hex(intval).replace(replacestr, '')])
  43.    
  44.     return macaddr.upper()
  45.  
  46. def IsScrewed():
  47.     try:
  48.         rmac = get_macaddress('10.0.0.1')
  49.     except:
  50.         return 1
  51.        
  52.     if "000000000000" != rmac:
  53.         return 1
  54.     return 0
  55.  
  56. if __name__ == '__main__':
  57.     print str(IsScrewed())
  58.  
  59.  
RAW Paste Data