lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Milind once stated:
> 
> From: Sean Conner <sean@conman.org> 
> > It was thus said that the Great Milind Gupta once stated:
> > > Hi,
> > >      I am trying to create a server client pair on the local network and I
> > > want to find out the IP address of the server. I tried the broadcast method
> > > but it doesn't work on my windows 7 machine. Is there a way I can get a
> > > list of devices in the network and try each one of them to find out the
> > > server? Even if this can be done is it a good idea to do it this way?
> > > 
> > >      Any help would be appreciated.
> > 
> >   Are you trying to write the client such that it can locate the server
> > without being configured with the server's IP address?
> 
> Thanks for rephrasing it. That is exactly what I want to do. Any suggestions? 

Sure.  Two decent ideas, plus one marginal (possibly bad) idea.

1).  Create DNS SRV records for your server, which would look somethin like:

_myservice._tcp.www.example.net. IN SRV 0 0 0 hostname.example.net.

Then your client just issues a DNS SRV request for that record [1], parse the
output [2], then to a DNS A request for hostname.example.net and you have
the IP address.

2).  Have the server bind to a multicast IP address [3][4] that is well
known.  Any traffic sent to a multicast address won't be routed outside the
local network; nor will it be subject to requests from outside the network
(since by default, multicast addresses aren't routed).  You can have the
server then respond back to the client with its (the server's) IP address.

3) (marginal, possibly bad idea): scan the local network looking for your
server.  This is just simply cycling through all possible IP addresses, for
example, 192.168.1.1 to 192.168.1.254 (for a typical, small, private
network).  This is marginal, because it takes time and a possibly bad idea,
for it might offend the sensibilities of the local network administrator.

  -spc 

[1]	RFC-2782 covers all the details about DNS SRV records.

[2]	There's a simple C library with Lua bindings: 
	https://github.com/spc476/SPCDNS

[3]	239.255.0.1 is a good one.  It's a multicast reserved for local
	services.

[4]	It has to be a UDP socket; TCP does not work over multicast.