Skip to main content

Arcadis is Hiring!!!

 ARCADIS IS HIRING!!! Company : Arcadia Position : Software Engineer Experience : Bs/Ms Degree : BS in CS Apply Link: Apply Here

IP address using Javascript

Javascript is unable to get (nor stores somewhere) the client IP, however javascript is able to create Http requests, and server side languages are able to retrieve the user public IP, so you could use this as advantage. In other words, if you want to retrieve the public IP of an user you'll depend from a request to any server in order to retrieve the IP. However, with the introduction of the WebRTC, you'll be able to retrieve the private IP of the user with a trick using RTCPeerConnection.




Using webRTC (get private IP)



The RTCPeerConnection interface allow you to create a WebRTC connection between your computer and a remote peer. However, we are going to create an "interrupted" version of it in order to retrieve the IP of the client using only javascript.
The createOffer method initiates the creation of a session description protocol (SDP) which offer information about any MediaStreamTracks attached to the WebRTC session, session, codes and any candidates already gathered by the ICE agents (which contains our goal, the IP).
In older versions, this method uses callbacks. However, now return a value based in a Promise that returns the information that we need when fullfilled:

Note: the pure javascript implementation will return the client private IP, not the public.


CODE:- 

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8" />
  <title>Ip address</title>
  <link rel="stylesheet" href="style.css" />
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
  <script type="text/javascript">
    var getIPAddress = function() {
      $.getJSON("https://jsonip.com?callback=?"function(data) {
        alert("Your IP address is :- " + data.ip);
      });
    };
  </script>
</head>

<body>
  <div>
    <h3>
      Get Client Machine IP Address using JavaScript and JSON
    </h3>
    
  </div>
</body>

</html>


OUTPUT:-

Get Client Machine IP Address using JavaScript and JSON

Cleck to get IP Address

Comments

Popular posts from this blog

Let's Start with the Internet Marketing | Affiliate Marketing

Digital Marketing is  that the act of promoting and mercantilism merchandise and services by leverage online selling ways like social media selling, search selling, and email marketing. At a high level, digital marketing refers to advertising delivered through digital channels like search engines, websites, social media, email, and mobile apps. Using these online media channels, digital marketing is that the method by which companies endorse goods, services, and brands. Consumers heavily depend upon digital means to research products. as an example, Think with Google marketing insights found that 48% of consumers start their inquiries on search engines, while 33% look to brand websites and 26% search within mobile applications. While modern-day digital marketing is an unlimited system of channels to which marketers simply must onboard their brands, advertising online is way more complex than the channels alone....

Hewlett Packard Enterprise

CMS INTERN JOB   At Hewlett Packard Enterprise, we bring together the brightest minds to create breakthrough technology solutions that advance the way people live and work. What sets us apart? Our people and our relentless dedication to helping our customers make their mark on the world. We are a team of doers, dreamers and visionaries; inspired by our purpose and driven by our strategy. We live by our three values: partner, innovate and act. Our legacy inspires us as we forge ahead, always pushing to discover what’s next. Every day is a new opportunity to advance and grow ourselves, our company and the industry. Some people call it an obsession, we call it a way of life. SOME INFORMATIONS AND BASIC REQUIREMENTS REGARDING THE JOB: Job ID: 1104914 Date Posted: 10/26/2021 Primary Location: Bangalore, Karnataka Other Locations: Bangalore, Karnataka, India,Chennai,TAMILNADU, India Job Category: Graduate Program and Internships Schedule: Full time Shift: No shift premium (India) Respons...