Java methods for obtaining local ip addresses
Several methods for obtaining local ip addresses in java
1. Obtain the local ip Address
System. out. println (InetAddress. getLocalHost (). getHostAddress ());
2. domain name resolution ip method
System. out. println (InetAddress. getByName ("www.sina.com.cn "));
3. How to obtain the ip address of the local egress (lan nat or how to find the ip address of the local egress switch)
Establish TCP, telnet, and mina communications.
Socket client = new Socket ("192.168.6.8", 80); System. out. println (client. getInetAddress (). getHostAddress ());
4. How to obtain the local Internet ip Address
Enter the ip address for Baidu search. The result is as follows:
You can write an http request at http://www.ip138.com/to return your Internet IP address.
5. java calls cmd to obtain the ip address through the pipeline runtime
6. other methods to obtain ip addresses using jndi
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.