Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to get public IP address in JavaScript | jQuery

How To Get Public IP Address In JavaScript | JQuery
In this article, we will see the multiple examples to get the public IP Address of a computer using JavaScript. 
You should check out the docs.

Example 1,
$.getJSON('http://ip-api.com/json?callback=?', function (data) {
    console.log(JSON.stringify(data, null, 2));
});

//The result of this API Returns-
{
  "status": "success",
  "country": "India",
  "countryCode": "IN",
  "region": "DL",
  "regionName": "National Capital Territory of Delhi",
  "city": "New Delhi",
  "zip": "110001",
  "lat": 28.6331,
  "lon": 77.2207,
  "timezone": "Asia/Kolkata",
  "isp": "Tata Communications Limited",
  "org": "Tata Communications Limited",
  "as": "AS4755 Tata Communications Limited",
  "query": "14.140.243.202"
}



Example 2,
$.getJSON('https://ipapi.co/json/', function (data) {
    console.log(JSON.stringify(data, null, 2));
});

//The result of this API Returns-
{
  "ip": "14.140.243.202",
  "city": "New Delhi",
  "region": "National Capital Territory of Delhi",
  "region_code": "DL",
  "country": "IN",
  "country_name": "India",
  "continent_code": "AS",
  "in_eu": false,
  "postal": "110001",
  "latitude": 28.6358,
  "longitude": 77.2245,
  "timezone": "Asia/Kolkata",
  "utc_offset": "+0530",
  "country_calling_code": "+91",
  "currency": "INR",
  "languages": "en-IN,hi,bn,te,mr,ta,ur,gu,kn,ml,or,pa,as,bh,sat,ks,ne,sd,kok,doi,mni,sit,sa,fr,lus,inc",
  "asn": "AS4755",
  "org": "TATA Communications formerly VSNL is Leading ISP"
}

Example 3,
$.getJSON('http://www.geoplugin.net/json.gp?jsoncallback=?', function (data) {
    console.log(JSON.stringify(data, null, 2));
});

//The result of this API Returns-
{
  "geoplugin_request": "14.140.243.202",
  "geoplugin_status": 200,
  "geoplugin_delay": "2ms",
  "geoplugin_credit": "Some of the returned data includes GeoLite data created by MaxMind, available from http://www.maxmind.com.",
  "geoplugin_city": "Chennai",
  "geoplugin_region": "Tamil Nadu",
  "geoplugin_regionCode": "TN",
  "geoplugin_regionName": "Tamil Nadu",
  "geoplugin_areaCode": "",
  "geoplugin_dmaCode": "",
  "geoplugin_countryCode": "IN",
  "geoplugin_countryName": "India",
  "geoplugin_inEU": 0,
  "geoplugin_euVATrate": false,
  "geoplugin_continentCode": "AS",
  "geoplugin_continentName": "Asia",
  "geoplugin_latitude": "13.0833",
  "geoplugin_longitude": "80.2833",
  "geoplugin_locationAccuracyRadius": "500",
  "geoplugin_timezone": "Asia/Kolkata",
  "geoplugin_currencyCode": "INR",
  "geoplugin_currencySymbol": "₹",
  "geoplugin_currencySymbol_UTF8": "₹",
  "geoplugin_currencyConverter": 70.7325
}

Example 4,
$.getJSON('http://gd.geobytes.com/GetCityDetails?callback=?', function (data) {
    console.log(JSON.stringify(data, null, 2));
});

//The result of this API Returns-
{
  "geobytesforwarderfor": "",
  "geobytesremoteip": "14.140.243.202",
  "geobytesipaddress": "14.140.243.202",
  "geobytescertainty": "99",
  "geobytesinternet": "US",
  "geobytescountry": "United States",
  "geobytesregionlocationcode": "USTX",
  "geobytesregion": "Texas",
  "geobytescode": "TX",
  "geobyteslocationcode": "USTXHOUS",
  "geobytesdma"


This post first appeared on Programming, please read the originial post: here

Share the post

How to get public IP address in JavaScript | jQuery

×

Subscribe to Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×