Created
February 16, 2017 14:53
-
-
Save Hanaasagi/22154a48de625582ac73047d4a94782a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*-coding:UTF-8-*- | |
# python2.x | |
import socket | |
import struct | |
import fcntl | |
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]) | |
if __name__ == '__main__': | |
print get_ip_address('wlan0') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment