Metainformationen zur Seite
  •  

Whois in Py

https://pypi.org/project/ip2geotools/
https://geocoder.readthedocs.io/api.html#ip-addresses

from ipwhois import IPWhois
from pprint import pprint
import sys
import geocoder
from ip2geotools.databases.noncommercial import DbIpCity
import socket
 
#IPs als Liste in Datei übergeben     
filepath = sys.argv[1]
 
with open(filepath,'r') as fp:
    #Kopfzeile fürs Wiki
    print("^ IP ^ FQDN ^ AS-Nummer ^ AS-Name ^ CIDR ^ City (ipinfo.io) ^ City (DbIpCity)^")
 
    #Datei Zeilenweise auslesen   
    for i in fp:
        line = i.rstrip(' \n')
        line = line.lstrip(' ')
        print("| "+ line + " | ", end='' )
 
        try:
            fqdn = socket.gethostbyaddr(line)
            domain = '.'.join(fqdn[0].split('.')[0:])
        except:
            domain = "x"
 
        try:
            g = geocoder.ipinfo(line) #Loc von ipinfo.io
 
        except:
            g = "x"
        try:
            response = DbIpCity.get(line,api_key='free')# Loc von DbIpCity
        except:
            response = "x"
        try:
            obj = IPWhois(line)
            results = obj.lookup_rdap(depth=1)#whois abfrage für ASN Daten
            print("{} | {} | {} | {} | {} | {} |".format(domain, results['asn'],results['asn_description'],results['asn_cidr'],g.city,response.city ))
        except:
            print("error | error | error | error | error |")