def main(): args = parse_args() ip = args['address'] verbose = args['verbose'] with open(os.path.join('data', 'iana_ip_base'), 'r') as db: iana_ip_base = dict() for line in db: key, value = line.strip().split(' ') iana_ip_base[key] = value ipregexp = re.compile(r'\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}') addrregexp = re.compile(r'.+?\s*?\[(?P<IP>.*?)\]') print('Tracing to %s\n' % ip) for n, info in enumerate(tracert.tracert(ip, verbose), 1): addr = info[-1] as_name = '' match = re.match(ipregexp, addr) if not match: match = re.match(addrregexp, addr) if match: addr = match.group('IP') if addr.split('.')[0] in iana_ip_base: rir = iana_ip_base[addr.split('.')[0]] as_info = dict() for field, value, comment in whois.whois_iter(rir, addr): if field == 'origin' or field == 'mnt-by': if field not in as_info: as_name += value + ' ' as_info[field] = value elif verbose: print('Can not find <%s> in iana ip base' % addr) if verbose: info_str = u'' for el in info[1:]: try: el_str = str(el) except UnicodeEncodeError: el_str += ' -TimeLimitExceeded' info_str += el_str + ' | ' else: info_str = addr print(u'%d\t%s\t%s' % (n, info_str, as_name if as_name else 'Unknown')) print('Completed')
# -*- coding: utf-8 -*- #/usr/bin/python2.7 from recvfile import recvfile from sendfile import sendfile from tracert import tracert import socket, time if __name__ == "__main__": s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) s.bind(('', 27015)) s.listen(100) print 'opened server\n' # for i in range(1): while True: sock, addr = s.accept() print time.ctime(), ':Connected by', addr recvfile(sock, 'host.txt') tracert('host.txt', 'result.txt') sendfile(sock, 'result.txt') sock.close()
from tracert import tracert from geolocateip import locate from kml import placemark, template with open("addresses.txt") as addresses: content = "" for address in addresses.readlines(): longlats = [ locate(x) for x in tracert(address) if locate(x) ] content += placemark(longlats) print template(content)