Last active
March 3, 2016 13:41
-
-
Save kacchan822/3120743d6050f2e04666 to your computer and use it in GitHub Desktop.
simple_whois.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
# | |
import sys | |
import ipaddress | |
from ipwhois import IPWhois | |
def swhois(ip): | |
obj = IPWhois(ip) | |
results = obj.lookup(get_referral=True) | |
cc = results['asn_country_code'] | |
cidrs = [] | |
for result_net in results['nets']: | |
cidr = result_net['cidr'].split('/')[1] | |
cidrs.append(int(cidr)) | |
ipwithcidr = str(ipaddress.IPv4Network(ip+'/'+str(max(cidrs)),False)) | |
return '{0} --> {1} {2}'.format(ip,ipwithcidr,cc) | |
if __name__ == '__main__': | |
print(swhois(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment