47 lines
884 B
Python
Executable File
47 lines
884 B
Python
Executable File
#!/usr/bin/env python
|
|
|
|
# Monitor Interfaces, send hb msg when add changes
|
|
import time, os, sys
|
|
|
|
SLEEP=60
|
|
SRV="colo2.wapanafa.org"
|
|
DBG=0
|
|
|
|
IFS=[]
|
|
f=os.popen('/sbin/ifconfig -a 2>/dev/null', 'r')
|
|
for l in f.readlines():
|
|
if len(l) > 1 and not l[0] in [' ','\t']:
|
|
r=l.split()
|
|
print r
|
|
if r[0][-1] == ':':
|
|
r[0]=r[0][:-1]
|
|
if r[0][:2] == 'lo':
|
|
continue
|
|
IFS.append(r[0])
|
|
if DBG: print IFS
|
|
addrs={}
|
|
for I in IFS:
|
|
addrs[I]=""
|
|
|
|
while 1:
|
|
|
|
for I in IFS:
|
|
f=os.popen('/sbin/ifconfig %s 2>/dev/null' % I, 'r')
|
|
for l in f.readlines():
|
|
r=l.split()
|
|
if DBG > 1: print "x2", r
|
|
if len(r) == 0 or r[0] != 'inet':
|
|
continue
|
|
if r[1].find('addr:') == 0:
|
|
iaddr=r[1][5:]
|
|
else:
|
|
iaddr=r[1]
|
|
if iaddr != addrs[I]:
|
|
msg='hbc -m "ifadd %s %s" %s' % (I, iaddr, SRV)
|
|
if DBG: print msg
|
|
else: os.system(msg)
|
|
addrs[I]=iaddr
|
|
f.close()
|
|
|
|
time.sleep(SLEEP)
|