I have this code to get an IP address in Android:
WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
Is there any easy way to convert this to a String?
Thanks.
--
--
You received
http://stackoverflow.com/questions/1957637/java-convert-int-to-inetaddress
On Mon, Feb 18, 2013 at 2:47 PM, bob wrote:
> I have this code to get an IP address in Android:
>
> WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
> WifiInfo wifiInfo = wifiManager.getConnectionInf
I forgot… I had this code already in my other project:
WifiManager wifiManager = (WifiManager)
getSystemService(Context.WIFI_SERVICE);
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
int ipAddress = wifiInfo.getIpAddress();
*String ip = String.format("%d.%d.%d.%d", (ipAddress & 0xff),*
* (i
If that gem ever shows up in one of my projects, I'll hunt you down
and give you a wedgie.
Larry
On Mon, Feb 18, 2013 at 3:11 PM, bob wrote:
> I forgot… I had this code already in my other project:
>
> WifiManager wifiManager = (WifiManager)
> getSystemService(Context.WIFI_SERVICE);
> WifiInfo
Why do you say that?
Here's another one if you don't like that one:
*public static String int_ip_to_string (int hostAddress) {*
*byte[] addressBytes = { (byte)(0xff & hostAddress),*
*(byte)(0xff & (hostAddress >> 8)),*
*(
On Tue, Feb 19, 2013 at 8:05 AM, bob wrote:
> Why do you say that?
Because it's a ridiculously obfuscated solution to a problem with a
simple one-line solution:
InetAddress address =
InetAddress.getByAddress(BigInteger.valueOf(actualIpAddressAsInt).toByteArray());
Larry
--
--
You received th
I actually happened upon that code today:
http://stackoverflow.com/questions/1221517/how-to-get-subnet-mask-using-java
private static String intToIP(int ipAddress) {
String ret = String.format("%d.%d.%d.%d", (ipAddress & 0xff),
(ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff),
Bob was asking for the string representation of an integer IP number. His
solution is correct, straightforward and does not require the instantiation
of three intermediate objects just for getting a simple string. Your
one-liner however creates a BigInteger, then a byte array and finally an
ins
Den tisdagen den 19:e februari 2013 kl. 18:30:45 UTC+1 skrev Nobu Games:
> Bob was asking for the string representation of an integer IP number. His
> solution is correct, straightforward and does not require the instantiation
> of three intermediate objects just for getting a simple string. Your
WifiInfo.getIpAddress() does not return IPv6 addresses. They do not fit
into a Java int.
On Wednesday, February 20, 2013 4:11:42 AM UTC-6, Jxn wrote:
>
> Den tisdagen den 19:e februari 2013 kl. 18:30:45 UTC+1 skrev Nobu Games:
> > Bob was asking for the string representation of an integer IP num
Hm, I'm a bit reluctant to post here, because when I wrote my previous post
on this thread I felt like letting off a bit of steam in defense of Bob. I
couldn't see what's so horribly wrong with his solution given this
particular context.
I agree with what you say and in general you're right wit
I am and trying to get an IP address of a mobile connection (the
emulator) with code. I will be using it later in the code, but I only
know how to how to get the IP of wifi.
Below is what I am trying now, but it comes back null. Does the
emulator just not able to get an IP or am I messing the c
12 matches
Mail list logo