简体   繁体   中英

How do I detect a server host:port on the local network?

I am sure there is a better way to describe the challenge I have, but hopefully this will be clear enough.

I have a server running on a random host + port within the local area network, I would like to know that hostname and port, or at least the random port, so that my (web) client can connect to the correct URL.

This specific server happens to run and respond to M-SEARCH (SSDP) queries, but I do not think you can query that from a webpage/javascript.

I don't mind using a common (cloud) server to help with the process.

edit: Come to think about it, I don't know what I was thinking about UPNP etc, my 'client' only has a browser and a url to provide, so I cannot run evena javascript before he hits my server:port. perhaps the solution has to be with some kind of well known address on the cloud or a well known port on the host.

You can use the netstat command to find the open ports on a server (windows or linux)

example on linux to find a java app server:

netstat -anp | grep java 

Output - it was listening on port 8080:

tcp        0      0 10.121.235.200:8080    0.0.0.0:*               LISTEN      7051/java

And as a side note, you may find this useful, if you have an idea it should be a certain port, you can check if there's a process running that is listening to it by using lsof:

lsof -i :portNumber

Example:

lsof -i :80

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM