Created
October 10, 2016 08:55
-
-
Save Jiezhi/31186ed7395a7039d3b4bca18eab7eb0 to your computer and use it in GitHub Desktop.
get net info, mac address, ip hostname
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
import uuid | |
import socket | |
import requests | |
def get_mac_address(): | |
mac = uuid.UUID(int = uuid.getnode()).hex[-12:] | |
return ":".join([mac[e:e+2] for e in range(0, 11, 2)]) | |
def get_name_and_address(): | |
myname = socket.getfqdn(socket.gethostname()) | |
ip = socket.gethostbyname(myname) | |
return myname, ip | |
if __name__=='__main__': | |
mac = get_mac_address() | |
name, inner_ip = get_name_and_address() | |
url = 'http://127.0.0.1:8000/tools/ip/?name=%s&mac=%s&inner_ip=%s' % (name, mac, inner_ip) | |
requests.get(url) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment