Search code examples
javawebserverport80

How to determine what server is listening on Port 80


I need to determine, what web server (IIS, Apache, Jetty) is running on port 80 in Java.

Are there any solutions to get the informations via port 80?

Thanx and reguards

Stefan


Solution

  • You can ask it - issue a HEAD request, e.g. open a TCP connection on port 80 and just send

    HEAD / HTTP/1.0
    

    or

    HEAD / HTTP/1.1
    Host: the.server.hostname.com
    

    and the reply should contain a Server line

    Server: Microsoft-IIS/5.1
    

    amongst other things.

    If you want to ask the OS which process, though, I don't know a Java-portable way. Command line you would run netstat -ano or (-anp on linux I think) which will give you the process number listening on port 80, and then you can look that up to find out exactly which server has the port.