SHARE
TWEET

Untitled

a guest May 24th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2. import fcntl
  3. import struct
  4.  
  5. def get_ip_address(ifname):
  6.     s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  7.     return socket.inet_ntoa(fcntl.ioctl(
  8.         s.fileno(),
  9.         0x8915,  # SIOCGIFADDR
  10.         struct.pack('256s', ifname[:15])
  11.     )[20:24])
  12.  
  13. get_ip_address('eth0')  # '192.168.0.110'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top