Difference between Internal IP Address and External IP Address

喜你入骨 提交于 2019-12-04 20:55:15

Internal IP address is the address from your network:

IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
IPAddress curAdd = heserver.AddressList[0];
curAdd.ToString();

Your external IP address is the address from your ISP

string ip = new 
     System.Net.WebClient()
      .DownloadString(("http://www.whatismyip.com/automation/n09230945.asp"));

You can use the following code (in java) to get the local IP address:

public String getLocalIpAddress() {
     try {
         for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
             NetworkInterface ni = en.nextElement();
             for (Enumeration enumIpAddr = ni.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                 InetAddress inetAddress = enumIpAddr.nextElement();
                 if (!inetAddress.isLoopbackAddress()) { //ignore 127.0.0.1
                     return inetAddress.getHostAddress().toString();
                 }
             }
         }
     } catch (SocketException ex) {
     }
     return null;
 }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!