shijuh
asked on
Check a Local IP to have http protocol
How do i check a system in the LAN is supporting http?
I often change my LAN settings(Internet options in IE
) to different machines depending upon the availability .
It is difficult for me to find which one is up.
Other wise i have to have the trail and error. If I have a program
where i can list all my IP's that displays the http status that
is easier for me to set the LAN settings...
I often change my LAN settings(Internet options in IE
) to different machines depending upon the availability .
It is difficult for me to find which one is up.
Other wise i have to have the trail and error. If I have a program
where i can list all my IP's that displays the http status that
is easier for me to set the LAN settings...
ASKER
Mig-O,
The logic seems to be OK !
It is therowing an error in
(NetworkInterface)interfac esEnum.nex tElement() ).
is it due the the lack of NetworkInterface class?
Shiju
The logic seems to be OK !
It is therowing an error in
(NetworkInterface)interfac
is it due the the lack of NetworkInterface class?
Shiju
I tried it with j2sdk1.4.1. A look into the documentation states, "NetworkInterface" exists since 1.4, so i believe you have 1.3 or lower on your machine.
An easier soultion would be to replace the Enumeration-while-stuff in main() with:
checkSubnet(InetAddress.ge tLocalHost ()), which is available since 1.0.
cheers,
Daniel Migowski
An easier soultion would be to replace the Enumeration-while-stuff in main() with:
checkSubnet(InetAddress.ge
cheers,
Daniel Migowski
Btw. a look into the documentation says:
public static Enumeration getNetworkInterfaces() throws SocketException
Returns all the interfaces on this machine. Returns null if no network interfaces could be found on this machine.
public static Enumeration getNetworkInterfaces() throws SocketException
Returns all the interfaces on this machine. Returns null if no network interfaces could be found on this machine.
ASKER
Daniel,
I have installed 1.4 and it is working now ...
But the output is not as par with my expectation !
The program is listing the computers having port 80.
I am connected in LAN. My internet access is through a
proxy server. I set this address and port in internet options. I want to know that is up and capable of
accepting http requests
Shiju
I have installed 1.4 and it is working now ...
But the output is not as par with my expectation !
The program is listing the computers having port 80.
I am connected in LAN. My internet access is through a
proxy server. I set this address and port in internet options. I want to know that is up and capable of
accepting http requests
Shiju
Add a loop for common proxyports to the code.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Would you please gimme the entire code . I am not that
familiar with java.I am compile, run and do small
modifications...
Shiju
familiar with java.I am compile, run and do small
modifications...
Shiju
shijuh:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
---------------------
import java.net.*;
import java.util.*;
public class SearchHTTPServers {
public static final ThreadGroup g = new ThreadGroup("Search Threads");
public static void main(String[] args) throws Exception {
Enumeration interfacesEnum =
NetworkInterface.getNetwor
while( interfacesEnum.hasMoreElem
Enumeration inetAddressEnum =
((NetworkInterface)interfa
getInetAddresses();
while( inetAddressEnum.hasMoreEle
InetAddress inetAddress = (InetAddress)inetAddressEn
nextElement();
checkSubnet(inetAddress);
}
}
while( true ) {
if(g.activeCount()==0) {
System.out.println("done."
break;
}
Thread.sleep(100);
}
}
public static void checkSubnet(InetAddress inetAddress) throws Exception {
byte[] address = inetAddress.getAddress();
for( int i=1; i<255; i++ ) {
String ip = (((int)address[0])+256)%25
(((int)address[1])+256)%25
(((int)address[2])+256)%25
i;
if( !ip.startsWith("127.0.0") ) {
new Thread( g,new CheckThread(ip) ).start();
}
}
}
static class CheckThread implements Runnable {
String ip;
public CheckThread(String ip) {
this.ip = ip;
}
public void run() {
try {
URL url = new URL("http",ip,80,"/");
url.openStream();
System.out.println(ip+" is up");
} catch( Exception e ) {
//System.out.println(ip+" is down");
}
}
}
}