Reputation: 51
I want to get all IP address ranges/blocks from as number. I can search throw google but need to write them manually. I want to get them all at once? Is this possible to get only ip address ranges from websites at once?
Upvotes: 4
Views: 5506
Reputation: 4721
Here's a simple one-liner using IP Guide, which is updated every 8 hours:
curl -sL https://ip.guide/as16509 | jq .routes
Which will return something like:
{
"v4": [
"1.44.96.0/24",
"2.57.12.0/24",
...
],
"v6": [
"2001:4f8:b::/48",
"2001:4f8:11::/48",
]
}
(jq isn't necessary here, but it helps traverse the JSON-based response)
Upvotes: 1
Reputation: 2175
If you don't have whois installed, you can achieve similar using a direct TCP connection to the WHOIS server.
For IPv4:
echo '-i origin AS15169' | nc whois.radb.net 43 | grep '^route:'
For IPv6:
echo '-i origin AS15169' | nc whois.radb.net 43 | grep '^route6:'
Similar can be achieved with Python using the socket
lib (in the standard library):
import socket
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(('whois.radb.net', 43))
s.sendall(b"-i origin AS15169\n")
result = ''
while True:
data = s.recv(16).decode('utf8')
if not data:
break
result += data
result = [i for i in result.split('\n') if i.startswith('route')]
print (result)
Upvotes: 4
Reputation: 354
sh ip bgp regex _<number>$
this shows the advertised netbocks from AS known to the local machine (on a cisco, quagga or FRR router). Some looking glasses will let you make this search (some won't).
Upvotes: -1
Reputation: 46
You can use whois servers instead of bgp.he.net or any other websites like this.
whois -h whois.radb.net -- '-i origin AS01' | grep 'route:'
Just run this command on your Linux machine.
Upvotes: 3