| #http://stackoverflow.com/questions/24196932/how-can-i-get-the-ip-address-of-eth0-in-python |
| s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) |
| return socket.inet_ntoa(fcntl.ioctl( |
| def gratuitousArp(intf, ip=None, mac=None): |
| #https://github.com/krig/send_arp.py/blob/master/send_arp.py |
| sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW) |
| sock.bind((intf, socket.SOCK_RAW)) |
| print 'Device does not exist: %s' % intf |
| print 'No IP for %s' % intf |
| packed_ip = pack('!4B', *[int(x) for x in ip.split('.')]) |
| packed_mac = pack('!6B', *[int(x,16) for x in mac.split(':')]) |
| packed_mac = sock.getsockname()[4] |
| bcast_mac = pack('!6B', *(0xFF,)*6) |
| zero_mac = pack('!6B', *(0x00,)*6) |
| eth_arp = pack('!H', 0x0806) |
| arp_proto = pack('!HHBBH', 0x0001, 0x0800, 0x0006, 0x0004, 0x0001) |
| sock.send(''.join(arpframe)) |
| if __name__ == "__main__": |
| intfs = os.listdir('/sys/class/net/') |