getByName() : Returns the InetAddress of the given host. If the host is a literal IP address, then only its validity is checked. Fetches public IP Address of the host specified. It takes the host as an argument and returns the corresponding IP address.
Input : www.google.com Output : 22.214.171.124 Input : localhost Output : 127.0.0.1
Below programs illustrate how to fetch public IP address:
Note: These programs wont run on online compilers. Use offline compilers like Netbeans, Eclipse, etc, instead.
Program 1: Fetch IP address of any url
Public IP Address of: www.google.com/126.96.36.199
Program 2: Fetch public IP address of the one’s system
To find public IP, use http://bot.whatismyipaddress.com. It is an online utility, to find system’s public IP. Open the URL, read a line and print the line.
Public IP Address: 188.8.131.52
Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: DSA Self Paced. Become industry ready at a student-friendly price.
- Finding DBA from given IP address
- Pinging an IP address in Java | Set 1
- How to validate an IP address using Regular Expressions in Java
- Pinging an IP address in Java | Set 2 (By creating sub-process)
- Check if email address valid or not in Java
- Java program to find IP address of your computer
- Difference Between Network Address Translation (NAT) and Port Address Translation (PAT)
- Difference between MAC Address and IP Address
- Finding minimum and maximum element of a Collection in Java
- How to validate an IP address using ReGex
- Compression of IPv6 address
- Extracting MAC address using Python
- Alias/Secondary IP Address
- Network Address Translation (NAT)
- Local Broadcast and Loopback Address
- Transition from IPv4 to IPv6 address
- Introduction of MAC Address in Computer Network
- C Program to display hostname and IP address
- Types of Network Address Translation (NAT)
- Difference between Static and Dynamic IP address
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.