What is my IP Address - How to find your IP address on Local Network using Command Prompt, and External Network using JavaScript Code

 


IP Address or Internet Protocol Address, is a set of numeric (IPv4) or Alphanumeric (IPv6) characters, which uniquely identify a system on the internet.

As per wikipedia:

An Internet Protocol address is a numerical label such as 172.16.254.1 that is connected to a computer network that uses the Internet Protocol for communication. An IP address serves two main functions: host or network interface identification and location addressing. Wikipedia

So, the next question is, what is my IP address? Now, there are two kinds of IP address, Internal IP - which identifies your machine on an internal network such as your home network connected to a router, and External IP, which identifies the network on the WWW i.e. the world wide web. 

Let's try to find our IP address!

To find your Internal IP address, you just need to know a few basic commands. 

Open the Command Prompt on a Windows machine, press Windows + R:


Click on OK.


Now, simply type the command - ipconfig

This simple command will give you your Internal IP address, both IPv4 and IPv6. 


Good!

Now, what about the external IP address?

The easy way is -> visit https://www.whatsmyip.org/

You instantly get your External IP details!

But we being technical persons, would want to build something of our own, right!

We'll utilize a free utility from Cloudflare https://www.cloudflare.com/cdn-cgi/trace

This simple utility directly responds with your IP address. Super! But we need a way to display that on the Webpage for our visitors.

Let's try to do that now. Below is a super simple form, and clicking on the button will call the above URL, get the IP details from the result and display it here.

Your IP Details



Here's how to create the form:


<form onsubmit="return false">
<p><b>Your IP Details</b></p>
  <p><span id="field_1"></span></p>
<br />
  <button id="calculatebtn" onclick="find_ip()" type="submit">Find My IP</button>
</form>


And, the core of this utility is the JavaScript used to get the data and display the results. Here is the JavaScript function:


function find_ip() {

    fetch(" https://www.cloudflare.com/cdn-cgi/trace").then(res => res.text()).then(data => {
        var ip = data.replace(/\r/g, "").split(/\n/);
        document.getElementById("field_1").innerHTML = ip[2];
    })

}


Super! Go ahead, use the code and build your own cool little utility!


Thanks for Reading the Article. If you have reached this far, we hope that the article was useful to you! Please Like/Share/Follow us on FacebookTwitterTumblr.





Comments

Popular posts from this blog

Calculate Your CTC Hike Percentage

Java Program to Find a List of Prime Numbers (Step by Step)

Java Program to check Palindrome

Reduce Server Load from Dynamic Page Search - Create a Dynamic JavaScript based Table filter