![JAR search and dependency download from the Maven repository](/logo.png)
com.viaoa.util.OANetwork Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of oa-core Show documentation
Show all versions of oa-core Show documentation
Object Automation library
/* Copyright 1999 Vince Via [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package com.viaoa.util;
import java.net.InetAddress;
public class OANetwork {
public static void findAllServers() throws Exception {
InetAddress localhost = InetAddress.getLocalHost();
byte[] ip = localhost.getAddress();
for (int i = 210; i <= 254; i++) {
ip[3] = (byte) i;
System.out.println(i+") ");
InetAddress address = InetAddress.getByAddress(ip);
String s = address.getHostAddress();
System.out.println(" "+address);
if (address.isReachable(250)) {
// machine is turned on and can be pinged
System.out.println(" reachable using ping");
continue;
}
System.out.println(" checking reverse DNS lookup");
String s2 = address.getHostName();
if (!s.equals(s2)) {
// machine is known in a DNS lookup
System.out.println(" reachable as "+address.getHostName());
}
else {
System.out.println(" not reachable");
// the host address and host name are equal, meaning the host name could not be resolved
}
}
}
public static void main(String[] args) throws Exception {
findAllServers();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy