Created
June 15, 2014 02:43
-
-
Save r1b/0f389089276739c50a37 to your computer and use it in GitHub Desktop.
Convert nirsoft country .csv ip ranges to nmap target selection format
This file contains hidden or 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
# I am not responsible &c | |
# RCJ 2014 | |
import sys | |
import requests | |
url = 'http://www.nirsoft.net/countryip/' + sys.argv[1] + '.csv' | |
r = requests.get(url) | |
if r.status_code != 200: | |
print "Bad country code: " + sys.argv[1] | |
sys.exit() | |
ifile = r.text.split('\r\n') | |
ofile = open(sys.argv[1] + '.nmap', 'w+') | |
for line in ifile: | |
if line == '': | |
continue | |
fields = line.split(',') | |
host1 = fields[0] | |
host2 = fields[1] | |
octets1 = host1.split('.') | |
octets2 = host2.split('.') | |
result = [] | |
for octet1, octet2 in zip(octets1, octets2): | |
if octet1 != octet2: | |
result.append(octet1 + '-' + octet2) | |
else: | |
result.append(octet1) | |
ofile.write('.'.join(result) + '\n') | |
ofile.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment