您可以使用其公开可用的 api 之一来解析域并获取 ip。您将在 Firefox 或 Chrome 插件脚本的 common.js 中找到 api urls 列表。
一个python例子,
import requests
from random import choice
def domain_ip(domain):
'''Uses bdns api to resolve domain names'''
domain = domain.split('/')[2] if '://' in domain else domain
apis = ['https://bdns.co/r/', 'https://bdns.us/r/', 'https://bdns.bz/r/']
api = choice(apis)
r = requests.get(api+domain)
if r.status_code == 200:
ip = r.text.splitlines()[0]
print("Domain: {} IP: {}".format(domain, ip))
return ip
else:
print('HTTP Error: {}'.format(r.status_code))
ip = domain_ip('http://jstash.bazar')
if ip:
r = requests.get('http://'+ip)
域名:jstash.bazar IP:190.115.24.114
21 年 10 月 20 日更新
Bdns 离线,我不知道他们是否会回来。我搜索了类似的公共 HTTP API,但找不到一个运行良好的 API。最好可以使用 Dnspython 查询 OpenNIC 服务器。
import dns.resolver
import requests
def domain_to_ip(domain, dns_server='159.89.120.99'):
'''Uses an OpenNIC server to resolve blockchain domains
:param domain: str Domain or URL
:param dns_server: str Optional, OpenNIC server
:raises dns.resolver.NXDOMAIN: if `dns_server` fails to resolve `domain`
'''
if '://' in domain:
domain = domain.split('/')[2]
res = dns.resolver.Resolver()
res.nameservers = [dns_server]
answers = res.resolve(domain)
return [rdata.address for rdata in answers]
ips = domain_to_ip('http://track2.bazar')
if ips:
r = requests.get('https://'+ips[0], verify=False)
print(r)
需要
dnspython,https://www.dnspython.org/
一个 OpenNIC dns_server, https://servers.opennicproject.org/
并且没有 SSL 验证verify=False。
非常感谢@VincentAlex 注意到这个问题并提出了解决方案。