?
Solved

Check  a Local IP to have http protocol

Posted on 2003-03-23
10
Medium Priority
?
224 Views
Last Modified: 2013-11-13
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...

0
Comment
Question by:shijuh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
10 Comments
 
LVL 3

Expert Comment

by:Mig-O
ID: 8193628
The following small program checks all addresses in you local subnets for Servers. Massively Multi-Threaded, btw. Enjoy.

---------------------

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.getNetworkInterfaces();
        while( interfacesEnum.hasMoreElements() ) {
            Enumeration inetAddressEnum =
                ((NetworkInterface)interfacesEnum.nextElement()).
                    getInetAddresses();
            while( inetAddressEnum.hasMoreElements() ) {
                InetAddress inetAddress = (InetAddress)inetAddressEnum.
                    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)%256+"."+
                        (((int)address[1])+256)%256+"."+
                        (((int)address[2])+256)%256+"."+
                        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");
            }
        }
    }
   
}


0
 

Author Comment

by:shijuh
ID: 8193891
Mig-O,
The logic seems to be OK !
It is therowing an error in
(NetworkInterface)interfacesEnum.nextElement()).
is it due the the lack of NetworkInterface class?

Shiju
0
 
LVL 3

Expert Comment

by:Mig-O
ID: 8194839
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.getLocalHost()), which is available since 1.0.

cheers,
Daniel Migowski

0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 3

Expert Comment

by:Mig-O
ID: 8194854
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.
0
 

Author Comment

by:shijuh
ID: 8200428
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

0
 
LVL 3

Expert Comment

by:Mig-O
ID: 8201241
Add a loop for common proxyports to the code.
0
 
LVL 3

Accepted Solution

by:
Mig-O earned 200 total points
ID: 8201267
Okey, i didn't understand before. You already know, which machines might be up.

Here you see how to set a proxy:

String url = "http://www.marchal.com/",
       proxy = "proxy.mydomain.com",
       port = "8080";
URL server = new URL(url);
Properties systemProperties = System.getProperties();
systemProperties.setProperty("http.proxyHost",proxy);
systemProperties.setProperty("http.proxyPort",port);
HttpURLConnection connection = (
    HttpURLConnection)server.openConnection();
connection.connect();
InputStream in = connection.getInputStream();
readResponse(in);

Now code something yourself, using the example, and check one after another, which of your selected machines are up.
0
 

Author Comment

by:shijuh
ID: 8207963
Would you please gimme the entire code . I am not that
familiar with java.I am compile, run  and do small
modifications...
Shiju
0
 

Expert Comment

by:CleanupPing
ID: 9446879
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.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Progress

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question