Back to cheatsheets
Developer
IP Address Lookup & Geolocation
Geolocate IP addresses, find ISP, ASN, country, and abuse contact information.
What you'll learn
- IP lookup via API
- ASN lookup via Team Cymru
How to use these snippets
- Click the Copy button next to any snippet to copy it to your clipboard.
- Paste the code into your project, IDE, or terminal.
- Replace placeholder values (like
example.comoryour-secret) with your actual data. - Review the code comments for important security notes and caveats.
- Try the interactive related tool to see the concept in action.
Code Snippets
Copy-paste code snippets
2 ready-to-use snippets for ip address lookup & geolocation. Click copy and paste into your project.
IP lookup via API
async function lookupIP(ip) {
// Using ipapi.co (free tier)
const res = await fetch(
`https://ipapi.co/${ip}/json/`
);
const data = await res.json();
return {
country: data.country_name,
city: data.city,
isp: data.org,
asn: data.asn,
timezone: data.timezone,
latitude: data.latitude,
longitude: data.longitude,
};
}
ASN lookup via Team Cymru
# Map IP to ASN via WHOIS
whois -h whois.cymru.com " -v 8.8.8.8"
# Output: AS|IP|BGP Prefix|CC|Registry|Allocated|AS Name
# Bulk ASN lookup
whois -h whois.cymru.com " -v 8.8.8.8,1.1.1.1"
# Find abuse contact
whois 8.8.8.8 | grep -i "abuse"
Tool
Related ShieldX tool
Try this concept hands-on with the interactive tool.
100% Free · No signup · No cost
Generate something unguessable right now
148 bits of entropy, a crack-time estimate you can trust, and a clipboard that clears itself after 30 seconds.
Part of the Toolly ecosystem · secure.toolly.site