域名(Domain Name)是由一串用点分隔的名字组成的Internet上某一台计算机或计算机组的名称,用于在数据传输时对计算机的定位标识。网络空间(Cyberspace)则是指由互联网构成的虚拟空间,包括所有通过网络连接的计算机、服务器、路由器等设备以及存储在这些设备上的数据和信息。
whois.domaintools.com
)来查询。nslookup
或 dig
命令进行DNS查询。ipinfo.io
)来查询。nmap
)来扫描。import whois
def query_whois(domain):
try:
result = whois.whois(domain)
print(result)
except Exception as e:
print(f"Error: {e}")
query_whois("example.com")
import dns.resolver
def query_dns(domain):
try:
answers = dns.resolver.resolve(domain, 'A')
for rdata in answers:
print(f"IP Address: {rdata}")
except Exception as e:
print(f"Error: {e}")
query_dns("example.com")
import requests
def query_ip_info(ip):
try:
response = requests.get(f"https://ipinfo.io/{ip}")
data = response.json()
print(data)
except Exception as e:
print(f"Error: {e}")
query_ip_info("8.8.8.8")
import socket
def scan_port(ip, port):
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(1)
result = sock.connect_ex((ip, port))
if result == 0:
print(f"Port {port} is open")
else:
print(f"Port {port} is closed")
sock.close()
except Exception as e:
print(f"Error: {e}")
scan_port("8.8.8.8", 80)
通过以上方法和工具,可以有效地查询域名及网络空间的相关信息,并解决常见的查询问题。
领取专属 10元无门槛券
手把手带您无忧上云