def test_ipv4_is_defined(self): try: from ipaddress import AddressValueError except ImportError: from ipaddr import AddressValueError self.assertRaises(ValueError, ipv4_is_defined, '192.168.0.256') self.assertRaises(AddressValueError, ipv4_is_defined, 1234) self.assertEquals(ipv4_is_defined('192.168.0.1'), (True, 'Private-Use Networks', 'RFC 1918')) self.assertEquals(ipv4_is_defined('74.125.225.229'), (False, '', ''))
def test_ipv4_is_defined(self): if sys.version_info >= (3, 3): from ipaddress import AddressValueError else: from ipaddr import AddressValueError self.assertRaises(ValueError, ipv4_is_defined, '192.168.0.256') self.assertRaises(AddressValueError, ipv4_is_defined, 1234) self.assertEquals(ipv4_is_defined('192.168.0.1'), (True, 'Private-Use Networks', 'RFC 1918')) self.assertEquals(ipv4_is_defined('74.125.225.229'), (False, '', ''))
def test_ipv4_is_defined(self): if sys.version_info >= (3, 3): from ipaddress import AddressValueError else: from ipaddr import AddressValueError self.assertRaises(ValueError, ipv4_is_defined, '192.168.0.256') self.assertRaises(AddressValueError, ipv4_is_defined, 1234) self.assertEquals(ipv4_is_defined('74.125.225.229'), (False, '', '')) self.assertEquals(ipv4_is_defined('0.0.0.0'), (True, 'This Network', 'RFC 1122, Section 3.2.1.3')) self.assertEquals(ipv4_is_defined('127.0.0.0'), (True, 'Loopback', 'RFC 1122, Section 3.2.1.3')) self.assertEquals(ipv4_is_defined('169.254.0.0'), (True, 'Link Local', 'RFC 3927')) self.assertEquals(ipv4_is_defined('192.0.0.0'), (True, 'IETF Protocol Assignments', 'RFC 5736')) self.assertEquals(ipv4_is_defined('192.0.2.0'), (True, 'TEST-NET-1', 'RFC 5737')) self.assertEquals(ipv4_is_defined('192.88.99.0'), (True, '6to4 Relay Anycast', 'RFC 3068')) self.assertEquals(ipv4_is_defined('198.18.0.0'), (True, 'Network Interconnect Device Benchmark Testing', 'RFC 2544')) self.assertEquals(ipv4_is_defined('198.51.100.0'), (True, 'TEST-NET-2', 'RFC 5737')) self.assertEquals(ipv4_is_defined('203.0.113.0'), (True, 'TEST-NET-3', 'RFC 5737')) self.assertEquals(ipv4_is_defined('224.0.0.0'), (True, 'Multicast', 'RFC 3171')) self.assertEquals(ipv4_is_defined('255.255.255.255'), (True, 'Limited Broadcast', 'RFC 919, Section 7')) self.assertEquals(ipv4_is_defined('192.168.0.1'), (True, 'Private-Use Networks', 'RFC 1918')) self.assertEquals(ipv4_is_defined('198.97.38.0'), (True, 'IANA Reserved', ''))
result = countries[script_args.get_country[0].upper()] print(('{0}Match found for country code ({1}){2}:\n{3}'.format( ANSI['green'] if script_args.colorize else '', script_args.get_country[0], ANSI['end'] if script_args.colorize else '', result))) except Exception as e: print(('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e)))) elif script_args.ipv4_is_defined: try: result = ipv4_is_defined(address=script_args.ipv4_is_defined[0]) if result[0]: print(('{0}{1} is defined{2}:\n{3}'.format( ANSI['green'] if script_args.colorize else '', script_args.ipv4_is_defined[0], ANSI['end'] if script_args.colorize else '', 'Name: {0}\nRFC: {1}'.format(result[1], result[2])))) else: print(('{0}{1} is not defined{2}'.format( ANSI['yellow'] if script_args.colorize else '', script_args.ipv4_is_defined[0], ANSI['end'] if script_args.colorize else ''))) except Exception as e:
print('{0}Match found for country code ({1}){2}:\n{3}'.format( ANSI['green'] if script_args.colorize else '', script_args.get_country[0], ANSI['end'] if script_args.colorize else '', result )) except Exception as e: print('{0}Error{1}: {2}'.format(ANSI['red'], ANSI['end'], str(e))) elif script_args.ipv4_is_defined: try: result = ipv4_is_defined(address=script_args.ipv4_is_defined[0]) if result[0]: print('{0}{1} is defined{2}:\n{3}'.format( ANSI['green'] if script_args.colorize else '', script_args.ipv4_is_defined[0], ANSI['end'] if script_args.colorize else '', 'Name: {0}\nRFC: {1}'.format(result[1], result[2]) )) else: print('{0}{1} is not defined{2}'.format( ANSI['yellow'] if script_args.colorize else '', script_args.ipv4_is_defined[0], ANSI['end'] if script_args.colorize else '' ))
except: output = req return (output) if __name__ == '__main__': args = parse_args() address = args.address filename = args.filename tsvoutfile = args.tsvoutfile if address: output = [] rfc1918 = ipv4_is_defined(address.strip()) if rfc1918[0]: result = [address.strip(), rfc1918[2], rfc1918[1], 'N/A'] else: obj = IPWhois(address.strip()) lookup = obj.lookup_rdap(asn_methods=['dns', 'whois', 'http']) reversedns = get_dns(address.strip()) result = [lookup['query'], lookup['asn_cidr'], lookup['asn_description'], reversedns] print_results(result) elif filename: filehandle = open(filename, 'r')