Home > Tricks & Tips > Get Current IP Address of Device

Get Current IP Address of Device


Here a quick snippet I wrote to get current IP of device.

public String getDeviceCurrentIPAddress() {
	static final String DOT = ".";
	WifiManager wifiManager = (WifiManager)getSystemService(WIFI_SERVICE);
	int IP = wifiManager.getConnectionInfo().getIpAddress();
	return (
		(( IP >> 24 ) && 0xFF ) + DOT +
		(( IP >> 16 ) && 0xFF ) + DOT +
		(( IP >>  8 ) && 0xFF ) + DOT +
		(  IP         && 0xFF )
	);
}

Cheers,

Pete Houston

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: