Last active
December 17, 2015 15:50
-
-
Save vicendominguez/0fe9acfe850a9c4a8d63 to your computer and use it in GitHub Desktop.
Get a name from the publicip and macaddrs
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
#!/usr/bin/python | |
import fcntl, socket, struct, urllib2 | |
def getHwAddr(ifname): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15])) | |
return '_'.join(['%02x' % ord(char) for char in info[18:24]]) | |
def getPublicAddr(): | |
r = urllib2.urlopen("http://ipinfo.io/ip") | |
ip = r.read(100) | |
return ip[:-1] | |
print getPublicAddr() + "-" + getHwAddr('eth0') |
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
root@raspberry:~# /usr/local/bin/get_macname.py | |
84.126.70.xx-b8_xx_eb_a4_xx_xc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment