pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Python pastebin - collaborative debugging tool View Help


Posted by DiabloHorn on Thu 25 Jun 21:09
report abuse | download | new post

  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())

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post