Source Documentation¶
Main API functionality
-
networktools.api.acl()[source]¶ Decorator that checks if visitor’s IP address is in the list of allowed IP addresses and aborts if it isn’t. Leave empty list in case you don’t want to use IP restrictions
-
networktools.api.error_response(msg, rc)[source]¶ Returns properly formatted error api response :param msg: Human readable error message :param rc: HTTP return code :return: JSON formatted error response
-
networktools.api.geoip_distance(lat1, long1, lat2, long2, metric=True)[source]¶ Calculates distance between two points on spherical earth.
Source: http://www.johndcook.com/blog/python_longitude_latitude/
Parameters: - lat1 – Latitude of the first point
- long1 – Longitude of the second point
- lat2 – Latitude of the second point
- long2 – Longitude of the second point
- metric – if true returns km, else returns miles
Returns: Distance in km
-
networktools.api.get_ipcalc_network(query, netmask='')[source]¶ IP calculator tool: supports IPv6 and IPv4 networks. For list of values see below.
IP list is optional since it will return many IPs for some subnets, if you need to show ip list you will have to append
?iplistto your get request.PLEASE NOTE: iplist will print only 65536 addresses which is /16 in IPv4 subnetting or /112 in IPv6 subnetting. If you try to get more you will get an error.
Parameters: - query – IP address or hostname
- netmask – (Optional) If you want the whole range of hosts
Example:
When getting single host
$ GET
/api/ipcalc/199.16.156.102/30{ "results": { "broadcast": "199.16.156.103", "cidr": "199.16.156.100/30", "first_host": "199.16.156.101", "hostmask": "0.0.0.3", "ip_bits": "11000111.00010000.10011100.01100110", "ip_version": 4, "is_linklocal": false, "is_loopback": false, "is_multicast": false, "is_private": false, "is_public": true, "is_reserved": false, "is_unicast": true, "last_host": "199.16.156.102", "netmask": "255.255.255.252", "netmask_bits": "11111111.11111111.11111111.11111100", "network": "199.16.156.100", "network_bits": "11000111.00010000.10011100.01100100", "num_addresses": 4, "prefixlen": 30, "supernet": [ "0.0.0.0/0", "128.0.0.0/1", "192.0.0.0/2", "192.0.0.0/3", "192.0.0.0/4", "192.0.0.0/5", "196.0.0.0/6", "198.0.0.0/7", "199.0.0.0/8", "199.0.0.0/9", "199.0.0.0/10", "199.0.0.0/11", "199.16.0.0/12", "199.16.0.0/13", "199.16.0.0/14", "199.16.0.0/15", "199.16.0.0/16", "199.16.128.0/17", "199.16.128.0/18", "199.16.128.0/19", "199.16.144.0/20", "199.16.152.0/21", "199.16.156.0/22", "199.16.156.0/23", "199.16.156.0/24", "199.16.156.0/25", "199.16.156.64/26", "199.16.156.96/27", "199.16.156.96/28", "199.16.156.96/29" ], "to_ipv6": "::ffff:199.16.156.102/126" }, "status": "ok" }
-
networktools.api.get_nmap_network(query, netmask='')[source]¶ Shows IP’s that are pingable and those that are not. Accepts netmask to define the whole range for scan. Uses NMAP’s -sP to probe hosts. Probing is done from Hosting machine and therefore not suitable for scanning local network ranges. Useful when checking how many IP’s you have left in a particular netmask.
Parameters: - query – IP address or hostname
- netmask – (Optional) If you want to scan the whole range of hosts
Example:
$ GET
/api/host/199.16.156.102/29{ "down": [ "199.16.156.100", "199.16.156.101", "199.16.156.96", "199.16.156.97", "199.16.156.98", "199.16.156.99" ], "hosts": [ { "host": "199.16.156.100", "hostname": [], "status": "down" }, { "host": "199.16.156.101", "hostname": [], "status": "down" }, { "host": "199.16.156.102", "hostname": [], "status": "up" }, { "host": "199.16.156.103", "hostname": [], "status": "up" }, { "host": "199.16.156.96", "hostname": [], "status": "down" }, { "host": "199.16.156.97", "hostname": [], "status": "down" }, { "host": "199.16.156.98", "hostname": [], "status": "down" }, { "host": "199.16.156.99", "hostname": [], "status": "down" } ], "status": "ok", "up": [ "199.16.156.102", "199.16.156.103" ] }
-
networktools.api.get_nmap_port(query, netmask=32)[source]¶ Scans host or whole subnet for hosts and their open ports. Uses NMAP’s -T4 -F params to probe hosts. Probing is done from Hosting machine and therefore not suitable for scanning local network ranges.
Parameters: - query – IP address or hostname
- netmask – (Optional) If you want to scan the whole range of hosts
Example:
$ GET
/api/nmap/199.16.156.102/30Returns:
{ "hosts": [ { "host": "199.16.156.102", "status": { "addresses": { "ipv4": "199.16.156.102" }, "hostnames": [], "status": { "reason": "syn-ack", "state": "up" }, "tcp": { "80": { "conf": "3", "cpe": "", "extrainfo": "", "name": "http", "product": "", "reason": "syn-ack", "state": "open", "version": "" }, "443": { "conf": "3", "cpe": "", "extrainfo": "", "name": "https", "product": "", "reason": "syn-ack", "state": "open", "version": "" }, "8888": { "conf": "3", "cpe": "", "extrainfo": "", "name": "sun-answerbook", "product": "", "reason": "syn-ack", "state": "open", "version": "" } }, "vendor": {} } }, { "host": "199.16.156.103", "status": { "addresses": { "ipv4": "199.16.156.103" }, "hostnames": [], "status": { "reason": "syn-ack", "state": "up" }, "tcp": { "80": { "conf": "3", "cpe": "", "extrainfo": "", "name": "http", "product": "", "reason": "syn-ack", "state": "open", "version": "" }, "443": { "conf": "3", "cpe": "", "extrainfo": "", "name": "https", "product": "", "reason": "syn-ack", "state": "open", "version": "" }, "8888": { "conf": "3", "cpe": "", "extrainfo": "", "name": "sun-answerbook", "product": "", "reason": "syn-ack", "state": "open", "version": "" } }, "vendor": {} } } ], "status": "ok" }
-
networktools.api.return_dns(query)[source]¶ DNS query, accepts IP or FQDN. FQDN is resolved to ip and then queried for dns data. You can specify multiple alternative DNS server to query by specifying
?q=<dns_ip1>,<dns_ip2>. If you do not specify DNS servers with?q=default server are8.8.8.8,8.8.4.4:returns Host records (A), MX records, NS records, SOA, TXT records
Parameters: query – IP or FQDN Example:
$ GET
/api/dns/1-up.xyz{ "hosts": { "records": [ { "address": "162.255.119.250", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "type": "A" } ] }, "mx": { "records": [ { "address": "eforward1.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "priority": "10", "type": "MX" }, { "address": "eforward4.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "priority": "15", "type": "MX" }, { "address": "eforward5.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "priority": "20", "type": "MX" }, { "address": "eforward2.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "priority": "10", "type": "MX" }, { "address": "eforward3.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "priority": "10", "type": "MX" } ] }, "ns": { "records": [ { "address": "dns2.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "type": "NS" }, { "address": "dns1.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "type": "NS" }, { "address": "dns3.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "type": "NS" }, { "address": "dns5.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "type": "NS" }, { "address": "dns4.registrar-servers.com.", "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "type": "NS" } ] }, "soa": { "records": [ { "class": "IN", "dns_contact": "hostmaster.registrar-servers.com.", "expire": "604800", "expires_in": "3600", "minimum": "3601", "name": "1-up.xyz.", "primary_ns": "dns1.registrar-servers.com.", "refresh": "43200", "retry": "3600", "serial": "2016031003", "type": "SOA" } ] }, "status": "ok", "txt": { "records": [ { "class": "IN", "expires_in": "1799", "name": "1-up.xyz.", "string": ""v=spf1 include:spf.efwd.registrar-servers.com ~all"", "type": "TXT" } ] } }
-
networktools.api.return_geoip(query)[source]¶ Geoip query, accepts IP or FQDN. FQDN is resolved to ip and then queried for geoip data. Google maps url in response for quick access. Distance available in metric and imperial measurements. Defaults to metric. Add
?imperialto get distance in miles.Parameters: query – IP or FQDN Example:
GET:
/api/nmap/8.8.8.8{ "geoip": [ { "area_code": 650, "city": "Mountain View", "continent": "NA", "country_code": "US", "country_code3": "USA", "country_name": "United States", "distance": 830 "distance_unit": "km" "dma_code": 807, "google_maps_url": "http://maps.google.com/maps?q=loc:37.386,-122.0838", "ip": "8.8.8.8", "isp": "Google", "latitude": 37.385999999999996, "longitude": -122.0838, "metro_code": "San Francisco, CA", "postal_code": "94040", "region_code": "CA", "time_zone": "America/Los_Angeles" }], "resolved_ips": [ "8.8.8.8" ], "status": "ok" }
-
networktools.api.return_ip()[source]¶ Curl / copy friendly external IP information. Could be wrong if behind proxy. :return: Public IP address of requestor
-
networktools.api.return_ipwhois(ipquery)[source]¶ IP whois query, accepts IP or FQDN. FQDN is resolved to ip and then queried for ipwhois data. Returns IP address and network’s registered user.
Parameters: ipquery – IP or FQDN Example:
GET:
/api/ipwhois/84.20.255.11{ ipwhois: [ { asn: "15169", asn_cidr: "8.8.8.0/24", asn_country_code: "US", asn_date: "", asn_registry: "arin", nets: [ { address: "1025 Eldorado Blvd.", cidr: "8.0.0.0/8", city: "Broomfield", country: "US", created: "1992-12-01", description: "Level 3 Communications, Inc.", emails: "noc.coreip@level3.com abuse@level3.com ipaddressing@level3.com", handle: "NET-8-0-0-0-1", name: "LVLT-ORG-8-8", postal_code: "80021", range: "8.0.0.0 - 8.255.255.255", state: "CO", updated: "2012-02-24" }, { address: "1600 Amphitheatre Parkway", cidr: "8.8.8.0/24", city: "Mountain View", country: "US", created: "2014-03-14", description: "Google Inc.", emails: "network-abuse@google.com arin-contact@google.com", handle: "NET-8-8-8-0-1", name: "LVLT-GOGL-8-8-8", postal_code: "94043", range: null, state: "CA", updated: "2014-03-14" } ], query: "8.8.8.8", raw: null, raw_referral: null, referral: null } ], status: "ok" } }
-
networktools.api.return_whatismyip()[source]¶ Simple page with user’s IP address information :return: What Is My IP page
-
networktools.api.return_whois(query)[source]¶ Whois query, accepts IP or FQDN. FQDN is resolved to ip and then queried for ipwhois data.
Parameters: query – IP or FQDN Example:
$ GET
/api/whois/1-up.xyz{ status: "ok", whois: { contacts: { admin: { city: "Panama", country: "PA", email: "5cc1435e8bae40bf8275d28a2150b6bf.protect@whoisguard.com", fax: "+51.17057182", handle: "C44073503-CNIC", name: "WhoisGuard Protected", organization: "WhoisGuard, Inc.", phone: "+507.8365503", postalcode: "00000", state: "Panama", street: "P.O. Box 0823-03411" }, billing: { city: "Panama", country: "PA", email: "5cc1435e8bae40bf8275d28a2150b6bf.protect@whoisguard.com", fax: "+51.17057182", handle: "C44073504-CNIC", name: "WhoisGuard Protected", organization: "WhoisGuard, Inc.", phone: "+507.8365503", postalcode: "00000", state: "Panama", street: "P.O. Box 0823-03411" }, registrant: { city: "Panama", country: "PA", email: "5cc1435e8bae40bf8275d28a2150b6bf.protect@whoisguard.com", fax: "+51.17057182", handle: "C44073500-CNIC", name: "WhoisGuard Protected", organization: "WhoisGuard, Inc.", phone: "+507.8365503", postalcode: "00000", state: "Panama", street: "P.O. Box 0823-03411" }, tech: { city: "Panama", country: "PA", email: "5cc1435e8bae40bf8275d28a2150b6bf.protect@whoisguard.com", fax: "+51.17057182", handle: "C44073507-CNIC", name: "WhoisGuard Protected", organization: "WhoisGuard, Inc.", phone: "+507.8365503", postalcode: "00000", state: "Panama", street: "P.O. Box 0823-03411" } }, creation_date: [ "Thu, 10 Mar 2016 12:13:09 GMT" ], emails: [ "abuse@namecheap.com" ], expiration_date: [ "Fri, 10 Mar 2017 23:59:59 GMT" ], id: [ "D18499062-CNIC" ], nameservers: [ "dns1.registrar-servers.com", "dns2.registrar-servers.com", "dns3.registrar-servers.com", "dns4.registrar-servers.com", "dns5.registrar-servers.com" ], raw: [ "Domain name: 1-up.xyz Registry Domain ID: D18499062-CNIC Registrar WHOIS Server: whois.namecheap.com ... For more information, please see https://registrar-console.centralnic.com/pub/whois_guidance. " ], registrar: [ "NAMECHEAP INC" ], status: [ "clientTransferProhibited", "serverTransferProhibited", "addPeriod" ], updated_date: [ "Thu, 10 Mar 2016 12:13:12 GMT" ], whois_server: [ "whois.namecheap.com" ] } }