4

Is it possible to find the ip of an http-server (which will respond on a specific request) in local network only via client javascript in the browser? It should work on mobile and desktop browsers. The poor mans way trying out all ip(v4) adresses seems not possible because I cannot get reliably the local ip (http://net.ipcalf.com doesn't work on IE and all mobile browsers on iOS). UDP broadcasts don't seem possible with javascript. Is there any other possibility?

My only other alternative seems to be developing a native discovery app for all relevant platforms (win, mac, ios, android).

3
  • You know, bro, your question sounds veeeeery fishy to me, like you wanna hack people. Commented Apr 18, 2015 at 10:44
  • 1
    @AntonMelnikov It's for a discovery service for a hardware appliance I'm building (user needs to find the configuration website for his new appliance in his own local network). This appliance has the server embedded. Commented Apr 20, 2015 at 14:40
  • Oh, ok, sorry for jumping to conclusions. Commented Apr 21, 2015 at 8:48

2 Answers 2

0

There's no purely client-side way to get that information, no. You'd have to query a site that provides DNS lookup with a cross-domain-friendly API, but that's not purely client-side.

1
  • I cannot make any assumptions of the availability of a DNS in the network knowing the server. In that case I could simply access the server by its name. Commented Apr 20, 2015 at 16:10
0

You just can guess the IP-Range of the local network and send multiple ajax requests to each IP in the Network. You will always get an error for each request, because if there isn't a timeout you get an No Access-Control-Allow-Origin error. However you can distinguish these errors by setting the timeout time to a certain time and track the time until the error occurs. If the tracked time is equal or bigger than your timeout you can suspect a timeout error. Otherwise you will get the error faster. So you can suspect that there is a server behind this IP.

Note: This is no secure method to search for servers and very CPU intensive.

4
  • As I control the server I could add an image to the website and check if it could be loaded instead of an more expensive (?) web request. But guessing the IP-Range is exactly the problem. Commented Apr 20, 2015 at 14:43
  • To load a image you also need a web (ajax-http) request. So loading an image is more expensive. However, when you get an error there is no expensiveness difference between loading an image and for example a textfile. Commented Apr 20, 2015 at 16:05
  • I meant adding the image to the DOM via the html img-tag. Commented Apr 20, 2015 at 16:08
  • Ok, but It will do a http request anyway. Manipulating the DOM would be even more expensive than directly sending the http request via ajax. Commented Apr 20, 2015 at 16:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.