Created
September 3, 2022 04:40
-
-
Save fishyer/5f14586527c94ab76bf9d54985717fd0 to your computer and use it in GitHub Desktop.
查询ip
This file contains 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
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