在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     }