解析域名并判断内外网ip
import socket import ipaddress from urllib.parse import urlparse def res(url): try: data = urlparse(url) domain = urlparse(url).netloc domain = domain.split(':')[0] res = socket.getaddrinfo(domain, None) print(res) ip = res[0][4][0] return ip except Exception as e: print(e) return "未知" def check_ip_valid(ip): try: ipaddress.ip_address(ip.strip()) return True except: return False def is_inner(ip): try: return ipaddress.ip_address(ip.strip()).is_private except: return False def check_domain(url): IP = res(url) if IP == "未知": return "-" if is_inner(IP): return "内网域名" else: return "外网域名"
每天逼着自己写点东西,终有一天会为自己的变化感动的。这是一个潜移默化的过程,每天坚持编编故事,自己不知不觉就会拥有故事人物的特质的。 Explicit is better than implicit.(清楚优于含糊)