Luasocket question

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Luasocket question

aryajur
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.

Thanks,
Milind
Reply | Threaded
Open this post in threaded view
|

Re: Luasocket question

Sean Conner
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?

  -spc





Reply | Threaded
Open this post in threaded view
|

Re: Luasocket question

aryajur
In reply to this post by aryajur
Thanks for rephrasing it. That is exactly what I want to do. Any suggestions? 



-------- Original message --------
From: Sean Conner <[hidden email]>
Date: 09/30/2013 5:49 PM (GMT-08:00)
To: Lua mailing list <[hidden email]>
Subject: Re: Luasocket question


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?

  -spc





Reply | Threaded
Open this post in threaded view
|

Re: Luasocket question

Sean Conner
It was thus said that the Great Milind once stated:

>
> From: Sean Conner <[hidden email]>
> > 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.

Reply | Threaded
Open this post in threaded view
|

Re: Luasocket question

Laurent FAILLIE
In reply to this post by aryajur

Hello,

I have installed Avahi on all my machines for this purposes : as far I know, it's also compatible with Apple's zeroconf.

For m$, I duno as I don't use those "technologies", but I'm sure they are using their own brodcast methods ... "network neighborhood" .

Bye


From: Milind Gupta <[hidden email]>
To: Lua mailing list <[hidden email]>
Sent: Tuesday, October 1, 2013 2:27 AM
Subject: Luasocket question

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.

Thanks,
Milind


Reply | Threaded
Open this post in threaded view
|

Re: Luasocket question

AllanPfalzgraf
In reply to this post by aryajur


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

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

Message: 5
Date: Tue, 1 Oct 2013 03:32:53 -0400
From: Sean Conner <[hidden email]>
Subject: Re: Luasocket question
To: Milind <[hidden email]>, Lua mailing list
        <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=iso-8859-1

It was thus said that the Great Milind once stated:

>
> From: Sean Conner <[hidden email]>
> > 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"))



Reply | Threaded
Open this post in threaded view
|

Re: Luasocket question

aryajur
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, <[hidden email]> wrote:


Allan Pfalzgraf
EATON
W126N7250 Flint Drive
Menomonee Falls, WI   53051
tel: <a href="tel:414%20449-6872" value="+14144496872">414 449-6872
fax: <a href="tel:414%20449-6616" value="+14144496616">414 449-6616
[hidden email]
www.Eaton.com <http://www.eaton.com/>

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

Message: 5
Date: Tue, 1 Oct 2013 03:32:53 -0400
From: Sean Conner <[hidden email]>
Subject: Re: Luasocket question
To: Milind <[hidden email]>, Lua mailing list
        <[hidden email]>
Message-ID: <[hidden email]>
Content-Type: text/plain; charset=iso-8859-1

It was thus said that the Great Milind once stated:
>
> From: Sean Conner <[hidden email]>
> > 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"))