According to China's national conditions, broadband sharing suffers from DNS pollution and HTTP interception is very serious, resulting in instability of network requests. But the IP/TCP agreement is generally unaffected. Therefore, the domain name can be resolved into IP and save, and then use IP access. The client initiates, resolves the domain name to the IP, if fails, tests the previous IP is usable and the Authentication IP authenticity (the same). If the domain name is resolved successfully, send encrypted information to the server to return the decrypted content to test the authenticity of the IP (guaranteed not to be contaminated by DNS). If possible, avoid using the HTTP protocol and use a custom protocol. For mobile clients, you can even use the mobile network to resolve the domain name, and then using the WiFi hotspot from the set up. The above method is only effective for the broadband detection after incomplete network disconnection.
Copy Code code as follows:
Import java.net.InetAddress;
Import java.net.UnknownHostException;
public class Parsedomainname {
InetAddress myServer = null;
InetAddress myipaddress = null;
String domainname = null;
Public Parsedomainname (String DomainName) {
This.domainname = domainname;
}
Public inetaddress Getserverip () {
try {
MyServer = inetaddress.getbyname (domainname);
catch (Unknownhostexception e) {
}
return (MyServer);
}
Get localhost IP address
Public inetaddress Getmyip () {
try {
myIpAddress = Inetaddress.getlocalhost ();
catch (Unknownhostexception e) {
}
return (myipaddress);
}
public static void Main (string[] args) {
Parsedomainname PDN = new Parsedomainname ("www.baidu.com");
System.out.println ("Your host IP is:" + Pdn.getmyip (). gethostaddress ());
System.out.println ("The Server IP is:" + Pdn.getserverip (). gethostaddress ());
}
}