Questions tagged [inetaddress]

227 questions
3
votes
4 answers

INetAddress Direct Instantiation

I'm fairly new to Java but not programming and I ran into this: InetAddress localAddress = InetAddress.getLocalHost(); It looked off to me. We're declaring localAddress as type InetAddress but it's being assigned an instance of a static method of…
user3743473
  • 45
  • 1
  • 5
3
votes
1 answer

How can I get domain name in Java

I need domain name. Currently I am getting domain name as follows InetAddress addr; String hostnameCanonical; try{ addr = InetAddress.getByName(InetAddress.getLocalHost().getHostName()); hostnameCanonical = addr.getCanonicalHostName(); …
Sachin
  • 247
  • 4
  • 16
  • 26
3
votes
1 answer

Return internal IP from NetworkInterface Android

I am using the code to grab the IPv4 address my device is using: public static String getIPAddress(boolean useIPv4) { try { List interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); for…
Dan
  • 2,304
  • 6
  • 42
  • 69
3
votes
2 answers

Odd InetAddress.isReachable() issue

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…
Jgregoire108
  • 109
  • 1
  • 9
3
votes
1 answer

Multi threaded UDP socket programming in Java

i just designed an application in Java to enable chat between multiple clients using one server. I used UDP sockets and multithreading. I had some questions about that: Client side code: private void sendMessage(String s) throws Exception { …
previouslyactualname
  • 703
  • 2
  • 11
  • 25
3
votes
3 answers

Safe method to get computer IP on UNIX using Java

I need to get computer IP from Ubuntu using Java. I tried with InetAddress.getLocalHost.getHostAddress().toString(); but it returns 127.0.0.1 . I was searching for solution and found out this code: NetworkInterface ni =…
user2496520
  • 881
  • 4
  • 13
  • 36
3
votes
2 answers

Different results between nslookup and Java's InetAddress getHostName

I'm trying to write a simple java program that will return the dns names of ip addresses which I do using the following code: InetAddress host = InetAddress.getByName(ip); String dnsName = host.getHostName(); When a dns name is registered…
Vasilis
  • 2,721
  • 7
  • 33
  • 54
2
votes
2 answers

Android - comparing two InetAddress which are equal fails?

I have an app that I am now developing multiplayer for. However I do not have 2 phones so I have been running a separate program on my pc (note: not the emulator!) which simulates my program and the multi-player aspects. However on the PC I have the…
iexus
  • 677
  • 11
  • 26
2
votes
0 answers

Java 11/17 HttpClient - How to try several IPs behind one hostname?

How can I configure Java's own "new" (Java 9/11/17) HttpClient to try more than the first found IP adress behind a hostname? There are (at least) two scenarios: A server with IPv4 and IPv6 support: > host localhost localhost has address…
Dirk Hillbrecht
  • 573
  • 5
  • 18
2
votes
0 answers

Scan and Get Hostname for all devices using Scala

I have the following snippet which attempts to print all available devices in the given IP range and I want it to also print the hostname: import java.net.{InetAddress, NetworkInterface} import scala.collection.JavaConverters._ object GetIpMac { …
joesan
  • 13,963
  • 27
  • 95
  • 232
2
votes
2 answers

IPv6ToBigInteger

I have this function which uses InetAddress, but the output is occasionally wrong. (example: "::ffff:49e7:a9b2" will give an incorrect result.) def IPv6ToBigInteger(ip: String): BigInteger = { val i = InetAddress.getByName(ip) val a:…
Hub
  • 23
  • 3
2
votes
3 answers

Threads getting into blocked state while doing a host name look up using java.net.InetAddress.getLocalHost

Please find below the application/environment details where the problem is seen. Java Web application deployed on Tomcat 9.0.35 with JRE Version 1.8.0_231-b11 The application is running in a docker container deployed on Open shift Kubernetes…
Sharath
  • 21
  • 2
2
votes
1 answer

Java: InetAddress.getLocalHost(); throws java.net.UnknownHostException

Im having a problem running my Java application: When the following line gets executed, it thows an exception: InetAddress.getLocalHost(); The following exception gets thrown: java.net.UnknownHostException: ????????: ???????? at…
Louis Bernard
  • 229
  • 4
  • 20
2
votes
2 answers

getLocalHost() shows wrong IP address

I am trying to execute following code. I am new to Java, so this is my first time in java.net. There is no error in program, but I am getting localhost address as 192.168.56.1 whereas my IP is 192.168.2.10 import java.net.*; class InetAddressDemo { …
Atharv Kurdukar
  • 115
  • 2
  • 12
2
votes
2 answers

Obtain ISP IP Address Android

Started working on a network monitoring app and I was wondering if there was a way to find out the ISP assigned IP address? I've looked into the Inet and WifiManager API's and all they seem to give you is your local network ip address. The code I…
Crouch
  • 846
  • 3
  • 17
  • 32