Questions tagged [inetaddress]

218 questions
99
votes
12 answers

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

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.
jiafu
  • 5,742
  • 10
  • 41
  • 69
88
votes
2 answers

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

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…
rob
  • 2,498
  • 5
  • 20
  • 37
42
votes
2 answers

Get IP address with URL string? (Java)

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…
user1205853
  • 621
  • 2
  • 8
  • 13
32
votes
1 answer

Host Name Vs Canonical Host Name

Can anyone please explain me the difference between Host Name and Canonical Host Name? I am currently using InetAddress class to fetch host name using the IP Address. I came across these 2 APIs. So I am just wondering, which one I should opt for?
Aryan
  • 1,467
  • 2
  • 19
  • 34
30
votes
10 answers

Java: convert int to InetAddress

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…
kdt
  • 26,008
  • 26
  • 82
  • 130
27
votes
5 answers

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

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?
TiansHUo
  • 8,049
  • 6
  • 42
  • 57
15
votes
2 answers

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

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…
Vishnudev K
  • 2,574
  • 3
  • 22
  • 42
13
votes
2 answers

How to store both IPv4 or IPv6 in single column in SQL Server?

Should I use binary(16) or varbinary(16)? I know I can use getAddress() in java.net.InetAddress (Java) or System.Net.IPAddress (C#) to get a byte[] representation of both IPv4 and IPv6, but if I need to insert IPv4 i.e. binary(4) into a binary(16)…
Henry
  • 31,972
  • 19
  • 112
  • 214
12
votes
3 answers

DNS query in JAVA

I am messing around with DNS services in Java - I am specifically trying to lookup all google.com addresses and display them in an array, similar to running a lookup using nslookup: nslookup -q=TXT _netblocks.google.com 8.8.8.8 I am using…
zJK
  • 121
  • 1
  • 1
  • 3
12
votes
1 answer

How can I bind serversocket to specific IP?

If I have a String representing an IP address (IPv4 or IPv6) how can I create a ServerSocket and bind to this IP without caring if the IP passed in, is IPv4 or IPv6? I see that there is a constructor:ServerSocket(int port, int backlog, InetAddress…
Jim
  • 17,102
  • 31
  • 115
  • 227
10
votes
1 answer

Java Getting IPv4 Address

Regarding this link where using the codes provided to produce the IP addresses. String ip; try { Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { …
Fouzy
  • 127
  • 1
  • 1
  • 6
9
votes
3 answers

Increment IP address

In that program I want to increment IP address. And I see output like that: 125.23.45.67 126.23.45.67 127.23.45.67 128.23.45.67 129.23.45.67 130.23.45.67 131.23.45.67 132.23.45.67 133.23.45.67 134.23.45.67 But I want to see output like…
d_pilot
  • 179
  • 1
  • 2
  • 12
9
votes
1 answer

JAVA Specifying port with InetAddress

I am using InetAddress to determine if my server is online. If the server is offline it will restart the server. This process loops every 5 minutes to check once again if the server is online. It works fine but now I need to figure out how to…
Cloudnine1999
  • 93
  • 1
  • 1
  • 5
8
votes
1 answer

Java InetAddress.isReachable() timeout

I am trying to find out if specific hosts on my network are reachable. My java code is as follows: InetAddress adr = InetAddress.getByName(host); if(adr.isReachable(3000)){ System.out.println(host + " is reachable"); } This works quite well,…
Jerome
  • 275
  • 2
  • 7
7
votes
3 answers

Obtain FQDN in Java

I am trying to obtain the FQDN of a windows machine in my domain, using Java code. I have tried the InetAddress.getByName("machine-1").getCanonicalHostName() but only returns the machine name. On the other hand if I ping "machine-1" I get the fully…
hgonzalez
  • 81
  • 1
  • 2
1
2 3
14 15