inetaddress

DNS query in JAVA

旧时模样 提交于 2019-12-04 04:49:41
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 InetAddress for this but keep on getting exception errors. Since the errors refer to 'Unknown Host' I don't think InetAddress can read TXT records (if I use google.com it works, but that does't show the full IP Range). Below is my code: InetAddress dnsresult[] = InetAddress.getAllByName("_netblocks.google.com"); for (int i=0; i<dnsresult.length; i++) System

JAVA Specifying port with InetAddress

痞子三分冷 提交于 2019-12-04 00:52:22
问题 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 specify that I want to use port 43594 when checking the server status instead of the default port 80. Thanks! Here's my code: import java.net.InetAddress; public class Test extends Thread { public static void main(String args[]) { try { while (true) {

Host Name Vs Canonical Host Name

早过忘川 提交于 2019-12-03 04:29:23
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? There are a few difference between the two: getCanonicalHostName() will attempt to resolve the FQDN . Therefore, you would get foo.mycompany.com whereas getHostName() might just return foo . getCanonicalHostName() will always do a reverse DNS lookup, whereas getHostName() would return the stored hostname if you supplied one in the InetAddress

How do I get host names by using IP, MAC addresses in android

纵饮孤独 提交于 2019-12-02 09:37:35
问题 I need to get the details of all wireless devices that are connected to my wifi network. I'm getting IP, MAC addresses, somehow Vendors of device as well. How do I get the device type? (i.e laptop, mobile, AC, Refrigerator) And host names? InetAddress inetAddress = null; for (int i = 0; i < 256; i++) { try { inetAddress = InetAddress.getByName("192.168.1." + i); if (inetAddress.isReachable(30)) { ConnectedDevice device = new ConnectedDevice(); device.setDeviceIPAddress(subnet + i); device

InetAddress java 8 is not getting the hostname

爷,独闯天下 提交于 2019-12-01 06:51:14
InetAddress.getLocalHost().getHostName() is no more getting the name of the HostName since I switched to java 8 ... with the jdk1.8 the InetAddress.getLocalHost().getHostName() returns "localhost". Before (when I was using jdk1.6) it gives me the right hostname (which is "ACTION03") according to the network config : cat /etc/sysconfig/network NETWORKING=yes HOSTNAME=ACTION03 any help ? Works for me on Linux (Ubuntu 14.04) with Java 1.8.0_05. public class HostName { public static void main(String[] args) throws Exception { System.out.println(java.net.InetAddress.getLocalHost().getHostName()); }

Java InetAddress.getHostName() taking a very long time to execute

白昼怎懂夜的黑 提交于 2019-12-01 06:18:59
I have the following little code snippet: InetAddress address = InetAddress.getByName(host); if(address.isReachable(TIMEOUT_IN_MILLISECONDS)) { System.out.println(host + " is reachable."); String hostName = address.getHostName(); System.out.println(hostName); } The getHostName() method is taking quite some time to execute if a machine has been found. Could someone please explain why? From the InetAddress#getHostName() javadocs , that method will perform a reverse hostname lookup . So the performance of that method call depends on the performance of the network/technology stack between the JVM

Java InetAddress.getHostName() taking a very long time to execute

夙愿已清 提交于 2019-12-01 04:11:12
问题 I have the following little code snippet: InetAddress address = InetAddress.getByName(host); if(address.isReachable(TIMEOUT_IN_MILLISECONDS)) { System.out.println(host + " is reachable."); String hostName = address.getHostName(); System.out.println(hostName); } The getHostName() method is taking quite some time to execute if a machine has been found. Could someone please explain why? 回答1: From the InetAddress#getHostName() javadocs, that method will perform a reverse hostname lookup. So the

JAVA Specifying port with InetAddress

帅比萌擦擦* 提交于 2019-12-01 04:06:37
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 specify that I want to use port 43594 when checking the server status instead of the default port 80. Thanks! Here's my code: import java.net.InetAddress; public class Test extends Thread { public static void main(String args[]) { try { while (true) { try { InetAddress address = InetAddress.getByName("cloudnine1999.no-ip.org"); boolean reachable = address

Increment IP address

只愿长相守 提交于 2019-12-01 03:25:17
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 this: 124.23.45.67 124.23.45.68 124.23.45.68 124.23.45.70 124.23.45.71 124.23.45.72 124.23.45.73 124.23.45.74 124.23.45.75 124.23.45.76 Here is program code: #include <stdlib.h> #include <stdio.h> #include <iostream> using namespace std; #include "winsock2.h" #pragma comment(lib,"wsock32.lib") void main() { in_addr adr1; in_addr adr2; int i; adr1.s_addr=inet

Increment IP address

大憨熊 提交于 2019-12-01 00:16:59
问题 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 this: 124.23.45.67 124.23.45.68 124.23.45.68 124.23.45.70 124.23.45.71 124.23.45.72 124.23.45.73 124.23.45.74 124.23.45.75 124.23.45.76 Here is program code: #include <stdlib.h> #include <stdio.h> #include <iostream> using namespace std; #include "winsock2.h"