import time
import socket
import uuid
import urllib
import urllib3
from urllib import request, parse
import json
def get_host_ip():
"""
:return: ip
"""
try:
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(('8.8.8.8', 80))
ip = s.getsockname()[0]
finally:
s.close()
return ip
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 send_post(url):
ip = get_host_ip()
print(ip)
mac = get_mac_address()
parms = {"ip":ip,"mac":mac}
querystring = parse.urlencode(parms)
u = request.urlopen(url, querystring.encode('utf-8'))
resp = u.read()
if __name__ == '__main__':
url = "http://simp00.top:9823/recv/"
while True:
try:
send_post(url)
time.sleep(20)
except Exception as e:
print(e)