inetaddress

Getting My LAN ip address (192.168.xxxx) (IPV4)

馋奶兔 提交于 2019-11-30 06:54:19
In my android device I am trying to find its IP address(IPV4). If I do the following code InetAddress inet = InetAddress.getLocalHost(); System.out.println(inet.getHostAddress()); //giving me 127.0.0.1 The code is giving me 127.0.0.1. I wanted to get the actual IP 198.168.xx.xx. (In My pc the same code giving me the actual IP though.) Ayush public static String getIpAddress() { try { for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements()

Java: convert int to InetAddress

℡╲_俬逩灬. 提交于 2019-11-28 21:09:52
I have an int which contains an IP address in network byte order, which I would like to convert to an InetAddress object. I see that there is an InetAddress constructor that takes a byte[] , is it necessary to convert the int to a byte[] first, or is there another way? This should work: int ipAddress = .... byte[] bytes = BigInteger.valueOf(ipAddress).toByteArray(); InetAddress address = InetAddress.getByAddress(bytes); You might have to swap the order of the byte array, I can't figure out if the array will be generated in the correct order. hbr Tested and working: int ip = ... ; String ipStr

Odd InetAddress.isReachable() issue

老子叫甜甜 提交于 2019-11-28 11:40:40
My work is developing software for network capable cameras for retail enviroments. One of the peices of software my team is developing is a webserver that retrieves various reports generated in HTML by the camera itself (which has its own embedded webserver) and stored on the camera. Our software will then GET these reports from the camera and store it on a central webserver. While we are fine plugging in the IPs of the cameras into our software, I am developing a simple Java class that will query the network and locate all cameras on the network. The problem though is that while it runs just

Is there an easy way to convert String to Inetaddress in Java?

99封情书 提交于 2019-11-28 06:58:19
问题 I am trying to convert strings into Inetaddress . I am not trying to resolve hostnames: the strings are ipv4 addresses. Does InetAddress.getByName(String host) work? Or do I have to manually parse it? 回答1: com.google.common.net.InetAddresses.forString(String ipString) is better for this as it will not do a DNS lookup regardless of what string is passed to it. 回答2: Yes, that will work. The API is very clear on this ("The host name can either be a machine name, such as "java.sun.com", or a

Java: Convert a String (representing an IP) to InetAddress [duplicate]

假如想象 提交于 2019-11-28 06:39:57
Possible Duplicate: Is there an easy way to convert String to Inetaddress in Java? I'm trying to convert a string(representing an IP address, e.g. 10.0.2.50 ) into an InetAddress obj. According to the API it is possible to create an Object providing a String representing a hostname (e.g. www.google.ch ). This is not an option for me since I do not have the hostname for each InetAddress object I want to create(besides that it takes too long). Is it possible to convert a String (e.g. 10.0.2.50 ) into an InetAddress obj.? (according to the api it is possible to do so if you have the IP as byte[]

Get IP address with URL string? (Java)

倖福魔咒の 提交于 2019-11-27 13:03:07
In my program a user enters a url string, say http://www.engineering.uiowa.edu/~hawkeng//fall01/graphics/potato.gif how would I get the IP address of this url? I tried using InetAddress address = InetAddress.getByName(urlStr); but the result always comes back null. What is the proper way to get the IP address? Try this: InetAddress address = InetAddress.getByName(new URL(urlString).getHost()); To get the raw IP: String ip = address.getHostAddress(); You need to give hostname to getByName() method and it returns the IP address of a host, given the host's name. URL url = new URL("http://www

Odd InetAddress.isReachable() issue

女生的网名这么多〃 提交于 2019-11-27 06:23:03
问题 My work is developing software for network capable cameras for retail enviroments. One of the peices of software my team is developing is a webserver that retrieves various reports generated in HTML by the camera itself (which has its own embedded webserver) and stored on the camera. Our software will then GET these reports from the camera and store it on a central webserver. While we are fine plugging in the IPs of the cameras into our software, I am developing a simple Java class that will

Java: Convert a String (representing an IP) to InetAddress [duplicate]

ぃ、小莉子 提交于 2019-11-27 01:26:33
问题 Possible Duplicate: Is there an easy way to convert String to Inetaddress in Java? I'm trying to convert a string(representing an IP address, e.g. 10.0.2.50 ) into an InetAddress obj. According to the API it is possible to create an Object providing a String representing a hostname (e.g. www.google.ch ). This is not an option for me since I do not have the hostname for each InetAddress object I want to create(besides that it takes too long). Is it possible to convert a String (e.g. 10.0.2.50

Get IP address with URL string? (Java)

只谈情不闲聊 提交于 2019-11-26 16:11:46
问题 In my program a user enters a url string, say http://www.engineering.uiowa.edu/~hawkeng//fall01/graphics/potato.gif how would I get the IP address of this url? I tried using InetAddress address = InetAddress.getByName(urlStr); but the result always comes back null. What is the proper way to get the IP address? 回答1: Try this: InetAddress address = InetAddress.getByName(new URL(urlString).getHost()); To get the raw IP: String ip = address.getHostAddress(); 回答2: You need to give hostname to

Why does InetAddress.isReachable return false, when I can ping the IP address?

♀尐吖头ヾ 提交于 2019-11-25 23:34:41
问题 InetAddress byName = InetAddress.getByName(\"173.39.161.140\"); System.out.println(byName); System.out.println(byName.isReachable(1000)); Why does isReachable return false ? I can ping the IP. 回答1: The "isReachable" method has not been worthy of using for me in many cases. You can scroll to the bottom to see my alternative for simply testing if you're online and capable of resolving external hosts (i.e. google.com) ... Which generally seems to work on *NIX machines. The issue There is alot of