#!/usr/bin/env python
from fcntl import ioctl
import socket
import struct
import sys
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
try:
#setup localhost IP address
ifreq = struct.pack('16sH2s4s8s', 'eth0', socket.AF_INET, '\x00' * 2, socket.inet_aton('192.168.0.1'), '\x00' * 8);
ioctl(sock.fileno(), 0x8916, ifreq)
#setup localhost IP Mask
ifreq = struct.pack('16sH2s4s8s', 'eth0', socket.AF_INET, '\x00' * 2, socket.inet_aton('255.255.255.255'), '\x00' * 8);
ioctl(sock.fileno(), 0x891c, ifreq)
#show localhost IP address
ip=ioctl(sock.fileno(),0x8915,struct.pack('64s','eth0'))
ip=socket.inet_ntoa(ip[20:24])
print ip
#setup localhost DNS
except:
print sys.exc_info()