lua-users home
lua-l archive

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


Thank you Sean and Allan. This really helps. I don't have much knowledge about DNS method, I will dig deeper in that. But I do know the server hostname so the dns.toip satisfies my requirement for now.

Thank you!
Milind



On Tue, Oct 1, 2013 at 6:08 AM, <AllanPfalzgraf@eaton.com> wrote:


Allan Pfalzgraf
EATON
W126N7250 Flint Drive
Menomonee Falls, WI   53051
tel: 414 449-6872
fax: 414 449-6616
AllanPfalzgraf@eaton.com
www.Eaton.com <http://www.eaton.com/>

------------------------------

Message: 5
Date: Tue, 1 Oct 2013 03:32:53 -0400
From: Sean Conner <sean@conman.org>
Subject: Re: Luasocket question
To: Milind <milind.gupta@gmail.com>, Lua mailing list
        <lua-l@lists.lua.org>
Message-ID: <20131001073253.GI25871@brevard.conman.org">20131001073253.GI25871@brevard.conman.org>
Content-Type: text/plain; charset=iso-8859-1

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.



------------------------------

Is the server known except for its IP address?  If it is the address can be derived from the system name.

local socket = require("socket")

local PORT = 55555   -- port for rack2 server_2000.lua
local HOST = socket.dns.toip("MKEWIWHP5012580") -- rack2 PC name
local rack2client = nil


if rack2client == nil then
    print("Attempting connection to host '" ..HOST.. "' and port " ..PORT.. "...")
    rack2client = assert(socket.connect(HOST, PORT))
    mb.delay(1000)
end

assert(rack2client:send("ioff\n"))