其他分享
首页 > 其他分享> > 获取本机160wifi IP

获取本机160wifi IP

作者:互联网

在wifi局域网中,数据交互需要用到此IP

 1     /**
 2      * 获取本机WIFI IP   for: 192.6.137.1
 3      * @return
 4      */
 5     public static String getlocalIP()
 6     {
 7         String ip="";
 8         InetAddress inet;
 9         try {
10             inet = InetAddress.getLocalHost();
11             InetAddress ias[]=InetAddress.getAllByName(inet.getHostName());
12             String addr;
13             for(InetAddress ia:ias)
14             {
15                 addr=ia.getHostAddress();
16                 if(addr.startsWith("192.") && addr.endsWith(".1"))
17                 {
18                     ip=addr;
19                     break;
20                 }
21             }
22 
23         } catch (Exception e) {
24             e.printStackTrace();
25         }
26         return ip;
27     }

 

标签:addr,160wifi,ip,IP,InetAddress,本机,inet,String
来源: https://www.cnblogs.com/du2022/p/15830120.html