handle many addresses per interface

This commit is contained in:
andreas
2012-03-29 02:08:57 +00:00
parent 61e70d824f
commit e09a23f572
+14 -9
View File
@@ -6,7 +6,9 @@ import time, os, sys
SLEEP=60
SRV="colo2.wapanafa.org"
DBG=0
HBC="/home/andreas/bin/hbc"
home=os.environ.get('HOME','/var/tmp')
HBC="%s/bin/hbc" % home
IFS=[]
f=os.popen('/sbin/ifconfig -a 2>/dev/null', 'r')
@@ -28,20 +30,23 @@ while 1:
for I in IFS:
f=os.popen('/sbin/ifconfig %s 2>/dev/null' % I, 'r')
ifaddrs=[]
for l in f.readlines():
r=l.split()
if DBG > 1: print "x2", r
if len(r) == 0 or r[0] != 'inet':
if len(r) == 0 or (r[0] != 'inet' and r[0] != 'inet6'):
continue
if r[1].find('addr:') == 0:
iaddr=r[1][5:]
ifaddr=r[1][5:]
else:
iaddr=r[1]
if iaddr != addrs[I]:
msg='%s -m "ifadd %s %s" %s' % (HBC, I, iaddr, SRV)
if DBG: print msg
else: os.system(msg)
addrs[I]=iaddr
ifaddr=r[1]
ifaddrs.append(ifaddr)
if ifaddrs != [] and ifaddrs != addrs[I]:
msg='%s -m "ifadd %s %s" %s' % (HBC, I, ",".join(ifaddrs), SRV)
if DBG: print msg
else: os.system(msg)
addrs[I]=ifaddrs
f.close()
time.sleep(SLEEP)