Dive into the Details: Python's IP Netblocks Decoder.

IP netblocks information use case.


Very often for webmasters or SEO professionals it is needed to retrieve IP netblocks information or even automate the process and there is a very useful online service for web developers and SEO professionals on "WhoisXML API" that provides Domain & IP Data Intelligence for Greater Enterprise Security and RESTful APIs that we will use.

Using it's APIs you can perform many handy data requests, for example you can get IP netblocks data - don't forget to get your API KEY. With one API call you will obtain ready to use parsed JSON file with a results of explicit information on the IP range that a given IP address belongs to, with detailed ownership information regarding each range.

IP netblocks data.
IP netblocks data meme.

Python Knowledge Base: Make coding great again.
- Updated: 2024-12-20 by Andrey BRATUS, Senior Data Analyst.




    This Python script below will use information from "WhoisXML API" and provide you a result in a JSON format without the need to use web a browser.
    The process of getting IP netblocks data can be easily automated now !


  1. Python code to retrieve IP netblocks data using API:


  2. 
    # IP Netblocks API USE
    
    import requests
    
    
    IP = '40.81.94.43'
    
    APIKEY ='at_ZUVkrukr4Uhhhsfq2j6dyv2VhFGWYV'
       
    
    IPNetblocksURL = f'https://ip-netblocks.whoisxmlapi.com/api/v2?apiKey={APIKEY}&ip={IP}&outputFormat=JSON'
    
    
    r = requests.get(IPNetblocksURL)
    
    IPNetblocks = r.json()
    
    print(f'IP Netblocks info for {IP} .\n')
    IPNetblocks
    


  3. IP netblocks data output:


  4. 
    IP Netblocks info for 40.81.94.43 .
    
    {'search': '40.81.94.43',
     'result': {'count': 6,
      'limit': 100,
      'from': '',
      'next': None,
      'inetnums': [{'inetnum': '40.80.0.0 - 40.95.255.255',
        'inetnumFirst': 281471358074880,
        'inetnumLast': 281471359123455,
        'inetnumFirstString': '281471358074880',
        'inetnumLastString': '281471359123455',
        'parent': '40.74.0.0 - 40.125.127.255',
        'as': {'asn': 8075,
         'name': 'MICROSOFT-CORP-MSN-AS-BLOCK',
         'type': 'Content',
         'route': '40.80.0.0/12',
         'domain': ''},
        'netname': 'MSFT',
        'nethandle': 'NET-40-74-0-0-1',
        'description': [],
        'modified': '2021-12-14T00:00:00Z',
        'country': 'US',
        'city': 'Redmond',
        'address': ['One Microsoft Way'],
        'abuseContact': [],
        'adminContact': [],
        'techContact': [],
        'org': {'org': 'MSFT',
         'name': 'Microsoft Corporation',
         'email': 'IOC@microsoft.com\nabuse@microsoft.com\niphostmaster@microsoft.com',
         'phone': '+1-425-538-6637\n+1-425-882-8080',
         'country': 'US',
         'city': 'Redmond',
         'postalCode': '98052',
         'address': ['One Microsoft Way']},
        'mntBy': [],
        'mntDomains': [],
        'mntLower': [],
        'mntRoutes': [],
        'remarks': [],
        'source': 'ARIN'},
       {'inetnum': '40.74.0.0 - 40.125.127.255',
        'inetnumFirst': 281471357681664,
        'inetnumLast': 281471361056767,
        'inetnumFirstString': '281471357681664',
        'inetnumLastString': '281471361056767',
        'as': None,
        'netname': 'MSFT',
        'nethandle': 'NET-40-74-0-0-1',
        'description': [],
        'modified': '2021-12-14T00:00:00Z',
        'country': 'US',
        'city': 'Redmond',
        'address': ['One Microsoft Way'],
        'abuseContact': [],
        'adminContact': [],
        'techContact': [],
        'org': {'org': 'MSFT',
         'name': 'Microsoft Corporation',
         'email': 'IOC@microsoft.com\nabuse@microsoft.com\niphostmaster@microsoft.com',
         'phone': '+1-425-538-6637\n+1-425-882-8080',
         'country': 'US',
         'city': 'Redmond',
         'postalCode': '98052',
         'address': ['One Microsoft Way']},
        'mntBy': [],
        'mntDomains': [],
        'mntLower': [],
        'mntRoutes': [],
        'remarks': [],
        'source': 'ARIN'},
       {'inetnum': '40.0.0.0 - 40.255.255.255',
        'inetnumFirst': 281471352832000,
        'inetnumLast': 281471369609215,
        'inetnumFirstString': '281471352832000',
        'inetnumLastString': '281471369609215',
        'as': None,
        'netname': 'NET40',
        'nethandle': 'NET-40-0-0-0-0',
        'description': [],
        'modified': '2012-11-13T00:00:00Z',
        'country': 'US',
        'city': 'Centreville',
        'address': ['PO Box 232290'],
        'abuseContact': [],
        'adminContact': [],
        'techContact': [],
        'org': {'org': 'ARIN',
         'name': 'American Registry for Internet Numbers',
         'email': 'hostmaster@arin.net\nnoc@arin.net',
         'phone': '+1-703-227-0660\n+1-703-227-9840',
         'country': 'US',
         'city': 'Centreville',
         'postalCode': '20120',
         'address': ['PO Box 232290']},
        'mntBy': [],
        'mntDomains': [],
        'mntLower': [],
        'mntRoutes': [],
        'remarks': [],
        'source': 'ARIN'},
       {'inetnum': '38.0.0.0 - 40.168.255.255',
        'inetnumFirst': 281471319277568,
        'inetnumLast': 281471363907583,
        'inetnumFirstString': '281471319277568',
        'inetnumLastString': '281471363907583',
        'as': None,
        'netname': 'NON-RIPE-NCC-MANAGED-ADDRESS-BLOCK',
        'nethandle': '',
        'description': ['IPv4 address block not managed by the RIPE NCC'],
        'modified': '2022-08-04T13:56:06Z',
        'country': 'EU',
        'city': '',
        'address': [],
        'abuseContact': [],
        'adminContact': [],
        'techContact': [],
        'org': None,
        'mntBy': [{'mntner': 'RIPE-NCC-HM-MNT', 'email': ''}],
        'mntDomains': [],
        'mntLower': [],
        'mntRoutes': [],
        'remarks': ['------------------------------------------------------',
         '',
         'For registration information,',
         'you can consult the following sources:',
         '',
         'IANA',
         'http://www.iana.org/assignments/ipv4-address-space',
         'http://www.iana.org/assignments/iana-ipv4-special-registry',
         'http://www.iana.org/assignments/ipv4-recovered-address-space',
         '',
         'AFRINIC (Africa)',
         'http://www.afrinic.net/ whois.afrinic.net',
         '',
         'APNIC (Asia Pacific)',
         'http://www.apnic.net/ whois.apnic.net',
         '',
         'ARIN (Northern America)',
         'http://www.arin.net/ whois.arin.net',
         '',
         'LACNIC (Latin America and the Carribean)',
         'http://www.lacnic.net/ whois.lacnic.net',
         '',
         '------------------------------------------------------',
         '****************************',
         '* THIS OBJECT IS MODIFIED',
         '* Please note that all data that is generally regarded as personal',
         '* data has been removed from this object.',
         '* To view the original object, please query the RIPE Database at:',
         '* http://www.ripe.net/whois',
         '****************************'],
        'source': 'RIPE'},
       {'inetnum': '0.0.0.0 - 255.255.255.255',
        'inetnumFirst': 281470681743360,
        'inetnumLast': 281474976710655,
        'inetnumFirstString': '281470681743360',
        'inetnumLastString': '281474976710655',
        'as': None,
        'netname': 'IANA-IPV4-MAPPED-ADDRESS',
        'nethandle': 'NET6-0-0-0-0-0-FFFF-1',
        'description': [],
        'modified': '2022-02-26T00:00:00Z',
        'country': 'US',
        'city': 'Los Angeles',
        'address': ['12025 Waterfront Drive', 'Suite 300'],
        'abuseContact': [],
        'adminContact': [],
        'techContact': [],
        'org': {'org': 'IANA',
         'name': 'Internet Assigned Numbers Authority',
         'email': 'abuse@iana.org',
         'phone': '+1-310-301-5820',
         'country': 'US',
         'city': 'Los Angeles',
         'postalCode': '90292',
         'address': ['12025 Waterfront Drive', 'Suite 300']},
        'mntBy': [],
        'mntDomains': [],
        'mntLower': [],
        'mntRoutes': [],
        'remarks': ['IPv4-mapped Address [RFC4291]'],
        'source': 'ARIN'},
       {'inetnum': ':: - ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff',
        'inetnumFirst': 0,
        'inetnumLast': 3.402823669209385e+38,
        'inetnumFirstString': '0',
        'inetnumLastString': '340282366920938463463374607431768211455',
        'as': None,
        'netname': 'IANA-BLK',
        'nethandle': '',
        'description': ['The whole IPv6 address space'],
        'modified': '2022-05-23T14:49:16Z',
        'country': 'EU',
        'city': '',
        'address': [],
        'abuseContact': [],
        'adminContact': [],
        'techContact': [],
        'org': {'org': 'ORG-IANA1-RIPE',
         'name': 'Internet Assigned Numbers Authority',
         'email': 'bitbucket@ripe.net',
         'phone': '',
         'country': '',
         'city': '',
         'postalCode': '',
         'address': ['see http://www.iana.org']},
        'mntBy': [{'mntner': 'RIPE-NCC-HM-MNT', 'email': ''}],
        'mntDomains': [],
        'mntLower': [{'mntner': 'RIPE-NCC-HM-MNT', 'email': ''}],
        'mntRoutes': [],
        'remarks': ['This network is not allocated.',
         'This object is here for Database',
         'consistency and to allow hierarchical',
         'authorisation checks.',
         '****************************',
         '* THIS OBJECT IS MODIFIED',
         '* Please note that all data that is generally regarded as personal',
         '* data has been removed from this object.',
         '* To view the original object, please query the RIPE Database at:',
         '* http://www.ripe.net/whois',
         '****************************'],
        'source': 'RIPE'}]}}
    




See also related topics: