域名IP查询大全:从命令行到在线工具,一网打尽!
要查询域名的IP地址,你可以使用多种方法,包括使用命令行工具、在线工具或编程语言。以下是一些常见的方法:
1. 使用命令行工具
1.1 nslookup
nslookup
是一个常用的命令行工具,用于查询域名的DNS记录。
示例:
nslookup example.com
输出:
Server: 192.168.1.1
Address: 192.168.1.1#53
Non-authoritative answer:
Name: example.com
Address: 93.184.216.34
1.2 dig
dig
是另一个强大的DNS查询工具,提供了更详细的DNS信息。
示例:
dig example.com
输出:
; <<>> DiG 9.10.6 <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12345
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 86400 IN A 93.184.216.34
;; Query time: 20 msec
;; SERVER: 192.168.1.1#53(192.168.1.1)
;; WHEN: Mon Oct 09 12:34:56 UTC 2023
;; MSG SIZE rcvd: 56
2. 使用在线工具
2.1 ipinfo.io
ipinfo.io
是一个在线工具,可以查询域名的IP地址。
示例:
访问 ipinfo.io 并输入域名 example.com
。
输出:
{
"ip": "93.184.216.34",
"hostname": "example.com",
"anycast": true,
"city": "Los Angeles",
"region": "California",
"country": "US",
"loc": "34.0522,-118.2437",
"org": "AS15133 EdgeCast Networks, Inc.",
"postal": "90012",
"timezone": "America/Los_Angeles",
"readme": "https://ipinfo.io/missingauth"
}
2.2 whatismyipaddress.com
whatismyipaddress.com
也提供了查询域名IP地址的功能。
示例:
访问 whatismyipaddress.com 并输入域名 example.com
。
输出:
IP Address: 93.184.216.34
3. 使用编程语言
3.1 Python
你可以使用Python的 socket
模块来查询域名的IP地址。
示例:
import socket
def get_ip_address(domain):
try:
ip_address = socket.gethostbyname(domain)
return ip_address
except socket.error as e:
return str(e)
domain = "example.com"
ip_address = get_ip_address(domain)
print(f"The IP address of {domain} is {ip_address}")
输出:
The IP address of example.com is 93.184.216.34
3.2 JavaScript
在Node.js中,你可以使用 dns
模块来查询域名的IP地址。
示例:
const dns = require('dns');
dns.lookup('example.com', (err, address, family) => {
if (err) {
console.error(err);
return;
}
console.log(`The IP address of example.com is ${address}`);
});
输出:
The IP address of example.com is 93.184.216.34
4. 使用API
4.1 ip-api.com
ip-api.com
提供了API接口,可以查询域名的IP地址。
示例:
使用 curl
命令查询:
curl http://ip-api.com/json/example.com
输出:
{
"status": "success",
"country": "United States",
"countryCode": "US",
"region": "CA",
"regionName": "California",
"city": "Los Angeles",
"zip": "90012",
"lat": 34.0522,
"lon": -118.2437,
"timezone": "America/Los_Angeles",
"isp": "EdgeCast Networks, Inc.",
"org": "EdgeCast Networks, Inc.",
"as": "AS15133 EdgeCast Networks, Inc.",
"query": "93.184.216.34"
}
通过这些方法,你可以轻松地查询域名的IP地址。