ip2city
v1.0.5
Published
Get address and location details from an IP using this package, works with both require and import
Downloads
20
Maintainers
Readme
ip2city
A simple NPM package to get location, ISP, and address continent continent_code country country_flag in World.
Documentation / References
Installation
npm install ip2cityUsage
Get Address Details by IP
Using CommonJS (require)
const { getAddressFromIP } = require("ip2city");
(async () => {
const ip = "11.97.212.12"; // Example IP address
const result = await getAddressFromIP(ip);
console.log("Address Info:", result);
})();Using ES Modules (import)
import { getAddressFromIP } from "ip2city";
const ip = "11.97.212.12";
const result = await getAddressFromIP(ip);
console.log("Address Info:", result);API Reference
getAddressFromIP(ip)
Fetch address, region, and ISP information from a given IP address.
Parameters:
ip(string) – the IPv4 or IPv6 address
Returns:
- Promise that resolves to an object with the following fields:
ip– IP Addresscontinent– Continent namecountry– Country namecountry_code– ISO code (e.g., "IN")region– State/Region namecity– City namelatitude, longitude– Coordinatesisp– Internet Service Providerorg– Organization nametimezone– Timezone string (e.g., "Asia/Kolkata")currency– Currency namecurrency_code– ISO currency codecurrency_symbol– Currency symbol
Example:
const { getAddressFromIP } = require("ip2city");
getAddressFromIP("11.97.212.12")
.then((data) => console.log("Address Info:", data))
.catch((err) => console.error(err));Example Output:
{
"ip": "11.97.212.12",
"type": "IPv4",
"continent": "Asia",
"continent_code": "AS",
"country": "India",
"country_code": "IN",
"country_flag": "https://cdn.ipwhois.io/flags/in.svg",
"region": "Maharashtra",
"city": "Mumbai",
"latitude": 19.0759837,
"longitude": 72.8776559,
"isp": "Hostinger International Limited",
"org": "HOSTINGER HOSTING",
"timezone": "Asia/Calcutta",
"currency": "Indian Rupee",
"currency_code": "INR",
"currency_symbol": "₹"
}Complete Usage Example:
const { getAddressFromIP } = require("ip2city");
(async () => {
const ipList = ["11.97.212.12", "8.8.8.8"];
for (const ip of ipList) {
const info = await getAddressFromIP(ip);
console.log(`\nIP: ${info.ip}`);
console.log(`Location: ${info.city}, ${info.region}, ${info.country}`);
console.log(`ISP: ${info.isp}`);
console.log(`Currency: ${info.currency_symbol} (${info.currency_code})`);
}
})();Example Output:
IP: 11.97.212.12
Location: Mumbai, Maharashtra, India
ISP: Hostinger International Limited
Currency: ₹ (INR)
