How do I issue multiple commands using telnet or netcat?

Planning for telnet on DHCP

  • I need some help on networking and ip addresses. I'm working on a project that uses a RN-XV Wifly module to connect to a home's wifi network. To use the device you will have a GUI that on the back-end telnets to the Wifly module and sends a serial string of commands. So if the Wifly address is 10.1.0.17, it would send: telnet 10.1.0.17 80 (text commands) ctrl^] (escape character) quit If you are using static ips on your home network, no problem. But if you use dhcp, which is the standard out-of-the-box for just about every wireless router out there... I don't know how people usually handle dhcp. Here's the order of events that concerns me. 1. Plug in device, it gets an IP address assigned from the wifi router using dhcp. 2. Get the IP address and write it into the script. 3. The script works, everything works, no problem. 4. Someone unplugs the device, and when it is plugged back in the router gives it a different dhcp address. 5. Now the script doesn't work because it is telneting to the wrong ip address. What is the best practice for handling that case? Is there a unique identifier you can assign to a device that abstracts the ip address? Like if I do "telnet bob 80" and something somewhere knows "bob" is 10.1.0.17, where it is smart enough that if the ip address changes, "bob" changes too? Thanks. I'm hoping for a solution that require no setting changes to the router, so changing to things like "dhcp and static ips" is not what I hope to do.

  • Answer:

    Is there a unique identifier you can assign to a device that abstracts the ip address? Like if I do "telnet bob 80" and something somewhere knows "bob" is 10.1.0.17, where it is smart enough that if the ip address changes, "bob" changes too? This is called DNS. You can set up a local dynamic DNS server, but that's more trouble than just setting up the device on static ip. You can also set up the device on static ip without changing the router. The average home network only has a half dozen devices at most, which gives you about 200 addresses to play with on the upper end of the dhcp range with very little risk of conflict.

BeeDo at Ask.Metafilter.Com Visit the source

Was this solution helpful to you?

Other answers

DHCP reservations, or else try to set a static address on the WiFly (I'm not familiar with that box, so I'm not sure what it can do) and adjust the DHCP pool to be smaller so that the WiFly's static address never gets issued to another box while WiFly is offline.

Sunburnt

I would say that best practice is to use DHCP + service discovery protocols, the same way network-enabled printers work. This requires no configuration by the user, it will work on networks using any range of IP addresses, and there's no possibility of conflicts between devices even if you have multiples on the same network. http://en.wikipedia.org/wiki/Bonjour_(software) is a pretty simple protocol, native to OS X, but there are lots of other implementations, including for http://gkaindl.com/software/arduino-ethernet/bonjour, Windows and http://en.wikipedia.org/wiki/Avahi_(software). The way it would work is that the device would publish a service record (with addServiceRecord if you used the previously linked library) with a service type like "BeeDoDevice._http" or "BeeDoDevice._MyProtocol". The front-end would do a search for services of the same type, and get back a list of addresses, ports and any additional config info you want to include--one for each device on the network.

jjwiseman

What I have seen most devices do is provide a software utility that runs on your PC/Mac and will scan and find the device/IP. If it has internet access, you could have it phone home to a server and have a web page that lists the local IP there.

wongcorgi

I think what you want is some kind of http://en.wikipedia.org/wiki/Zero_configuration_networking beyond DHCP. There are off-the-shelf protocols that can be used. Failing that, you could use TCP/IP multicast to have the script broadcast a message to everything on the subnet, but that's likely to annoy people if it gets deployed on something other than a home LAN. Some routers will also respect local DNS hostname requests, but my anecdotal experience with that on my Linksys router is that it's very fragile.

qxntpqbbbqxl

If you use a router that uses http://www.thekelleys.org.uk/dnsmasq/doc.html as its DHCP and DNS server, when a device gets an IP from DHCP it will register that device's hostname in DNS. So given your "bob" example above, you set your device to have "bob" as the hostname and you can indeed do "telnet bob 80". I use this all the time both at home and work and it works very well. I know that ASUS's line of routers that use their Asuswrt firmware have dnsmasq out of the box. Such devices are the RT-N16, RT-N66U, and RT-N66AC. Dnsmasq is also part of http://www.dd-wrt.com/, so if you have a router that supports DD-WRT you may be in luck.

zsazsa

The way I would solve your problem is that the device would contact a central server (e.g. on the internet or "in the cloud") on assignment of an IP address. The device would then register a unique device ID with the server, so that there is a connection between "current device IP" and "device ID". This can be done with an outgoing telnet session from the device, simulating HTTP. Oh, and you might want to blink a led as this happens, so that the user knows the device is online. The "device ID" should be printed on the device itself. The first time the GUI starts it should ask for the device ID (for the user to type in), and for every startup it should query the central server for the local IP. This way the GUI app could (at least in theory) be some form of web app as well. Your main problem would probably be that nearly all wifi networks uses authentication, in various forms, and this authentication would have to happen before the DHCP address is assigned.

Baron Humbert von Gikkingen

Unless the Wi-Fly or your Arduino has a DHCP client that supports dynamic DNS, in which case you would have a hostname that the device itself could update its IP for, you want to use a http://www.tech-faq.com/dhcp-reservation.html that ties an IP address to a particular MAC address for the device, so the Arduino/WiFly will always have the same internal IP. Consult your DHCP server's documentation for more information, most do have this capability.

rhizome

I'm currently back to my ZTE modem, but the 2-Wire (which I think is now Pace) modem that I was using for some testing of fancy hardware on my ADSL2+ line a few months back was extremely good at remembering MAC addresses and always re-assigning the same DHCP address to a given MAC address. (Had a few other glitches, which is why I'm back to the ZTE, but I really liked that about it!) You can also put a MAC address in a DHCP pool with 1 IP address on the DHCP server that comes with most Linux distributions, and a quick Google search suggests that Cisco gear can be made to give a specific DHCP address to a given MAC address. How much control over your DHCP server do you have?

straw

Why is this device set to DHCP? Give it a static IP. If not, you'll need to set your DHCP server to do a reservation to use the same IP. One of the other, there's no other solution here. Well, there's DNS, but i imagine if getting DHCP to do a reservation is off the table, then DNS is also.

damn dirty ape

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.