How do I open web servers on my local network?

Suppose I run several servers serving basic requests on my local network (for example, a home network where all computers usually have an IP address in the form KKKx, where x is a variable). Is there an easy way to find all such servers? I will need to find every IP address on the network that is running a specific Java server application.

+2


a source to share


5 answers


So you have a class C network ... just try to open a specific server application port on every IP address between 1 and 254. If you want to get fancy you can do some checks to make sure if the port does open it does what you expect from this app.



+2


a source


Are you looking for a solution in your Java application? If you're just looking for a one-off solution, nmap should work.

If your local network is 192. *. *. * try this (I added sudo because it needs to be run as root):



sudo nmap -vv -sS -O -n "192.168.1.1/24"

      

+4


a source


Since not every web server listens on a fixed port 80

, you will need to scan for ports. Open (and close!) In a loop the socket on each port you can use java.net.Socket

. If successful, run a simple GET request on /

the appropriate IP port, you can use java.net.URLConnection

. If you receive a valid HTTP response (regardless of the status code), then it is the web server. The server type can be identified by the header Server

in the HTTP response. However, you need to take into account that the default response header can be started / removed / changed by the server administrator.

Note that some firewalls may recognize the port scanner scan pattern and block it.

+1


a source


There are two main ways to achieve this, and both require you to send / receive packets to / from each host you want to test.

  • The easiest way is to establish a TCP connection on the desired port as usual.

  • A more complex and quirky approach, but faster in terms of execution, sends a SYN packet and waits for a reply packet. If the response is SYN / ACK it means the port is open (waiting for a connection), otherwise it is not. However Java does not provide the required API (see raw socket ) to do this. You will need to find a library / wrapper or write it with C and JNI.

For more information on the second option, read this .

+1


a source


I would scan the IP range and check the socket connection to port 80 with code like this:

try {
       s = new Socket(addr,80);
       System.out.println("Webserver found on IP:" + addr );
       s.close();
     }
catch (IOException ex) {
       System.out.println("Webserver NOT found on IP:" + addr );
    }

      

0


a source







All Articles