Skip to content

Instantly share code, notes, and snippets.

@fishyer
Created September 3, 2022 04:40
Show Gist options
  • Save fishyer/5f14586527c94ab76bf9d54985717fd0 to your computer and use it in GitHub Desktop.
Save fishyer/5f14586527c94ab76bf9d54985717fd0 to your computer and use it in GitHub Desktop.
查询ip
from http.server import BaseHTTPRequestHandler, HTTPServer
import socket
class handler(BaseHTTPRequestHandler):
def do_GET(self):
path = str(self.path)
try:
domain = path[path.rindex("/")+1:]
print(domain)
ip = socket.gethostbyname(domain)
except:
text = 'path is: %s, \n Error happens\n'%(path)
else:
text = 'domain is: %s \n ip is: %s\n'%(domain, ip)
self.send_response(200)
self.send_header('Content-type', 'text/plain')
self.end_headers()
self.wfile.write(text.encode())
return
if __name__ == "__main__":
http_server = HTTPServer(('', int(8888)), handler)
http_server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment