Created
January 26, 2018 11:35
-
-
Save andrewn/b5069ed83a0be201ee732beb2fd06f53 to your computer and use it in GitHub Desktop.
Revisions
-
andrewn created this gist
Jan 26, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,2 @@ http://forums.whirlpool.net.au/archive/1473574 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,27 @@ #!/usr/bin/python import socket # Open a raw socket listening on all ip addresses sock = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_ICMP) sock.bind(('', 1)) try : while True : # receive data data = sock.recv(1024) # ip header is the first 20 bytes ip_header = data[:20] # ip source address is 4 bytes and is second last field (dest addr is last) ips = ip_header[-8:-4] # convert to dotted decimal format source = '%i.%i.%i.%i' % (ord(ips[0]), ord(ips[1]), ord(ips[2]), ord(ips[3])) # Flash LED # Play a sound print 'Ping from %s' % source except KeyboardInterrupt : print ''