Skip to content

Instantly share code, notes, and snippets.

@n0ts
Created October 9, 2012 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0ts/3856376 to your computer and use it in GitHub Desktop.
Save n0ts/3856376 to your computer and use it in GitHub Desktop.
macrefresh.py
#!/usr/bin/python
#
# macrefresh.py : Update MAC Table with broadcast ARP
#
# 2011/01/23 ver1.0
#
# /etc/rc.local => /usr/local/script/macrefresh.py 1>/dev/null 2>&1 &
import socket
import fcntl
import sys
import os
import time
#--------------------------#
IfaceList = [ "eth0", "eth1" ]
Interval = 10
#--------------------------#
def ifconfig(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
result = fcntl.ioctl(s.fileno(), 0x8915, (ifname+'\0'*32)[:32])
except IOError:
return None
return socket.inet_ntoa(result[20:24])
if __name__ == '__main__':
ipaddr = {}
for iface in IfaceList:
ipaddr[ iface ]= ifconfig( iface )
while( 1 ):
for iface in IfaceList:
os.system( "arping -c 1 -I " + iface + " " + ipaddr[ iface ] + ">/dev/null 2>&1" )
time.sleep( Interval )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment