user1372896
user1372896

Reputation: 534

Get IP's in Autonomous System Number (ASN)

I've tried getting the list of IP's under an ASN number for example AS8167 however I am having no such luck. I have seen that team cymru have an IP to ASN, however that is the opposite of what I actually need.

Upvotes: 9

Views: 6765

Answers (3)

bswinnerton
bswinnerton

Reputation: 4721

You can use IP Guide to look up the IPs announced by an ASN with something like this:

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)

Or if you're looking for a way to do this in PHP:

<?php

// Initialize cURL session
$curl = curl_init('https://ip.guide/as16509');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);

$response = curl_exec($curl);
curl_close($curl);

$data = json_decode($response, true);

if (isset($data['v4']) && isset($data['v6'])) {
    echo "IPv4 Routes:\n";
    foreach ($data['v4'] as $route) {
        echo $route . "\n";
    }

    echo "\nIPv6 Routes:\n";
    foreach ($data['v6'] as $route) {
        echo $route . "\n";
    }
} else {
    echo "Error: Invalid response from API";
}

?>

Upvotes: 1

Ben Dowling
Ben Dowling

Reputation: 17541

RADb has a whois server that provides this functionality. It includes information other than just the IP blocks, so you'll need to grep for those if that's all you're interested in:

$ whois -h whois.radb.net -- '-i origin AS8167' | grep -Eo "([0-9.]+){4}/[0-9]+" | head
189.11.64.0/18
189.31.0.0/16
189.72.128.0/18
189.73.192.0/18
189.74.0.0/18
189.74.64.0/18
189.64.0.0/11
189.0.0.0/11
187.52.192.0/18
187.52.0.0/17

Upvotes: 13

Steve
Steve

Reputation: 3046

Hurricane Electric has a service that was made specifically for this and other IP related purposes.

Try this: http://bgp.he.net/AS8167#_prefixes

Upvotes: 4

Related Questions