Get Wifi IP

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Get Wifi IP

Postby puxdroid » Mon Jan 11, 2010 10:32 am

Anybody knows how to get the Wifi IP?

I have tried this code, but give me the loopback IP

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. InetAddress thisIp;
  3.  
  4.                 try {
  5.  
  6.                         thisIp = InetAddress.getLocalHost();
  7.  
  8.                         mTexServerInfo.setText(thisIp.getHostAddress());
  9.  
  10.                 } catch (UnknownHostException e) {
  11.  
  12.                         mTexServerInfo.setText("Error obtaining the local address");
  13.  
  14.                         Log.e(TAG, "ERROR obtaining the local address", e);
  15.  
  16.                 }
  17.  
  18.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


Thanks in advance!
puxdroid
Developer
Developer
 
Posts: 49
Joined: Wed Nov 25, 2009 11:57 am

Top

Re: Get Wifi IP

Postby puxdroid » Mon Jan 11, 2010 12:06 pm

I have solved the problem. Use this code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         private String getWifiIp() {
  3.  
  4.                 WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
  5.  
  6.  
  7.  
  8.                 int ip = wifiManager.getConnectionInfo().getIpAddress();
  9.  
  10.                 return (ip & 0xFF) + "." + ((ip >> <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" /> & 0xFF) + "."
  11.  
  12.                                 + ((ip >> 16) & 0xFF) + "." + ((ip >> 24) & 0xFF);
  13.  
  14.  
  15.  
  16.         }
  17.  
  18.  
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
puxdroid
Developer
Developer
 
Posts: 49
Joined: Wed Nov 25, 2009 11:57 am

Re: Get Wifi IP

Postby lizemountain » Fri Jan 22, 2010 10:54 am

puxdroid wrote:I have solved the problem. Use this code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private String getWifiIp() {
  2.                 WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
  3.  
  4.                 int ip = wifiManager.getConnectionInfo().getIpAddress();
  5.                 return (ip & 0xFF) + "." + ((ip >> <img src="http://www.anddev.org/images/smilies/cool.png" alt="8)" title="Cool" /> & 0xFF) + "."
  6.                                 + ((ip >> 16) & 0xFF) + "." + ((ip >> 24) & 0xFF);
  7.  
  8.         }
  9.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


it's a good method!
thanks!
lizemountain
Once Poster
Once Poster
 
Posts: 1
Joined: Fri Jan 22, 2010 10:51 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 5 guests