get ip address javascript

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 <a href='http://www.maxmind.com'>http://www.maxmind.com</a>.",
  "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": "618",
  "geobytescity": "Houston",
  "geobytescityid": "11109",
  "geobytesfqcn": "Houston, TX, United States",
  "geobyteslatitude": "29.771601",
  "geobyteslongitude": "-95.392998",
  "geobytescapital": "Washington",
  "geobytestimezone": "-06:00",
  "geobytesnationalitysingular": "American",
  "geobytespopulation": "278058881",
  "geobytesnationalityplural": "Americans",
  "geobytesmapreference": "North America ",
  "geobytescurrency": "US Dollar",
  "geobytescurrencycode": "USD",
  "geobytestitle": "The United States"
}

Example 5,
$.getJSON("http://jsonip.com/?callback=?", function (data) {
    console.log(JSON.stringify(data));
});

//The result of this API Returns-
{
    "ip": "14.140.243.202",
    "about": "https://jsonip.com/about",
    "Pro!": "http://getjsonip.com",
    "Get Notifications": "https://jsonip.com/notify"
}

You must see this - How to Get Public IP Address Using C#
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

How to get public IP address in JavaScript | jQuery How to get public IP address in JavaScript | jQuery Reviewed by Anil Singh on 12:55 AM Rating: (5)
www.code-sample.com/. Powered by Blogger.
^