Created
October 9, 2012 03:19
-
-
Save n0ts/3856376 to your computer and use it in GitHub Desktop.
macrefresh.py
This file contains 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 characters
#!/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