How to get the ip ranges of domain

1. 获取想访问的的IP RANG(这里的RANG可以不全),这里以GITHUB为例, 得到图(1)的结果(以免DNS污染,建议使用国外DNS):
dig github.com TXT @8.8.8.8

 

 

2. 从whois.radb.net 获取组织AS NAME,或者从这个链接直接获取AS NAME[https://bgp.potaroo.net/as1221/asnames.txt]:

whois -h whois.radb.net 192.30.255.113 | grep origin 

 

 

3. 从whois.radb.net 获取IP RANGE.

whois -h whois.radb.net -- '-i origin AS36459' | grep -Eo "([0-9.]+){4}/[0-9]+"

 

 

 

参考资料及文章:
https://qastack.cn/superuser/405666/how-to-find-out-all-ip-ranges-belonging-to-a-certain-as

https://ipinfo.io

https://www.radb.net/

https://bgp.potaroo.net/as1221/asnames.txt

 

根据AS NAME 获取 IP RANGE的PYTHON 脚本:

import requests
from bs4 import BeautifulSoup
import re


url_base = 'http://ipinfo.io/'
as_base = 'AS'

output = open('ip_per_asn.csv', 'w')
with open('chilean_asn.csv') as f:
    lines = f.read().splitlines()
    for asn in lines:
        ASN = as_base + asn
        page = requests.get(url_base+ASN)
        html_doc = page.content
        soup = BeautifulSoup(html_doc, 'html.parser')
        for link in soup.find_all('a'):
            if asn in link.get('href'):
                auxstring = '/'+as_base+asn+'/'
                line = re.sub(auxstring, '', link.get('href'))
                printstring = asn+','+line+'\n'
                if 'AS' not in printstring:
                    output.write(printstring)
        print asn+'\n'

print 'script finished'
posted @ 2023-01-14 11:33  CalvinChu  阅读(45)  评论(0编辑  收藏  举报