#!/usr/bin/python
import socket
import fcntl
import struct
import os
def get_ip_address(ifname):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
return socket.inet_ntoa(fcntl.ioctl(
s.fileno(),
0x8915, # SIOCGIFADDR
struct.pack('256s', ifname[:15])
)[20:24])
#print get_ip_address('eth0')
if __name__ == "__main__":
try:
IP = get_ip_address('tun0')
if IP:
print IP
except IOError,e:
os.system('cd /home/cluster/open*** && sudo /usr/sbin/open*** --config /home/cluster/open***/client.o*** >/var/log/open***.log &')