Can an AppleScript (with the help of a OSAX) or a shell script communicate via UDP over a particular port?
Google was my friend: sendip for which source is available for Linux. Now if I can figure out how to compile if for OS X, I’m golden. I understand that this can be done with Python too, but I don’t know the language.
Further research reveals that Bash can do it (at least in Linux) – something like: echo “hello” > /dev/udp/192.168.2.101/58549, assuming the required port was 58549. Don’t know whether that works in OS X.
Hello Adam.
I think that would work under OS X as well.
At least I think you can resort to Curl for sending a packet or two as well, not sure about the UDP protocol though, but there should be plenty of options. netcat being the first coming to my mind, I also thing nawk is good at it.
I have recently ported the old venerable index program (from 1989) to Mac Os X, made it use UTF-8 and ncurses and localized, so it uses proper collation order for the various languages. Here it is: Removed due to more bugs in the memory managment
I think I can help you compile sendip should you need some help with it.
Thanks – I’ll struggle a bit more – I don’t yet own the device that can run on commands via UDP over Wi-Fi, but I wanted to make sure that if I buy it, I can communicate with it. The UDP commands I care about get/set the state of 8 110v/10a relays.
Good luck!
It sounds fun and unsecure!
Hopefully you can protect your devices somehow.
Maybe you even can use the Apache Server that comes preinstalled to communicate with the devices? (Through some cgi scripting and perl? There is also WireShark, that can be handy when you want tolook at what is going on. (Packet analyzer, free). That is, to inspect that what you send is what you intended.
I couldn’t help it, saw it in NY Times today.
Back to the boring business of learning how to write portfiles, and the autotools!
Hello.
I think it is also possible to request a port of something useful on the MacPorts mailing list, if one for one reason or the other declines to build it oneself, or just feels it should be publically available on OS X.
Thanks for the ideas. I’ve also discovered that the bash ‘nc’ (netcat) function can send and receive text via UDP over an assigned port and given the simplicity of what I want to send and receive, it might do nicely.
I agree that naked the device would be insecure, but it can be passworded, it will be inside my LAN assigned a local IP Address by my AirPort Extreme. I don’t intend to port forward from the Internet to it as I have no need to communicate with it from outside the house. What I have in mind is to build an 8-recepticle power bar so a script (or script app) can set them on or off (powered or not) individually. I’ll use this initially as a wake-from-sleep script to turn on lights, printer, external speakers, etc. when I wake my Mac and turn them off again when the Mac goes to sleep. I’ll use Scenario to trigger the scripts.
Interesting, best of luck!
Wireshark may be very handy in figuring out what is going on with packets though, once you have learned to interpret them. I think there are many places on the internet that specifies the format of UDP packets, which varies slightly from regular TCP packts. but both being wrapped up inside ip-packets.
Well the password protection is only for web interface not for UDP (source:Labotronik) communication; It’s wide open. But as you already mentioned, it’s secured by routing. However I saw on their page that you can upload your own websites, so when you’re able to create an XML-RPC or SOAP interface I would give it a try. Also you can use curl to communicate send the right data to the web-server. When using an XML-RPC server, which I don’t know if possible, your AppleScript would look very clean:
tell application "http://relay-card"
(*since SL web service's xml element "member" and "methodName" values are no longer converted to lower case, which makes it case sensitive. Therefore I use method names only in lower case format to be sure the data in pre-SL version of OS X sends the same XML format as SL and newer. no camelStyle*)
call xmlrpc {method name:"port.setstate", parameters:{portnr:1, onstate:true}}
end
will send:
<methodCall>
<methodName>port.setstate</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>portnr</name>
<value>
<int>1</int>
</value>
</member>
<member>
<name>onstate</name>
<value>
<boolean>1</boolean>
</value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
Hello.
I’d rather deal with as much of the security by hardware as possible.
One approach would be to have all of the devices hanging on the same wifi router with static Ip-addresses.
The machine(s) you use to control them with should also have static IP-addresses.
The wifi router should have NAT (Network address translation). The machine you use to control the devices with, should also have a static Ip address. The wifi router with the devices should block all UDP traficc, except for udp traffic from your machine. It should be fairly safe. Anyone interested in hacking your devices would then have to put a considerable effort into getting at them, provided you have a fairly good password with say 30 characters, and the “new type” of password encryption. AES-2?
An even simpler layout, would be if your wifi router had subnets, and that both your machines and routers could “hang” on the same router, as you then could have everything routed internally without any outside expousure.
10A: it gave me some associations of the electrical fences of my childhood.
While I agree that both of these approaches (thanks for them) would be more secure than what I’d proposed, there is also the issue of what could happen if someone did get access to the device. Remember that, combined with a set of 110v electrical outlets and some wiring, all this device would do is turn those outlets on or off so the risk must factor in whether I care if a lamp comes on or goes off.
A further point is that the device has an Ethernet port and will reside close to my Airport Extreme. I could plug it in directly with a short cable and turn off its Wi-Fi radio, I think.
I understand where you’re coming from. And I agree that when the router denies access from the outside, it’s secure enough. I suggested XML-RPC as an alternative, nothing to do with security, so you have an interface to your device that is accessible from every programming language (even like JavaScript, bash, C (and supersets), ActionScript, C# (silverlight), PHP, perl, etc…). That would for me be ‘the’ reason to choose web services over UDP connection. I’m using XML-RPC (self written with SOAP and JSON-RPC) for years know and it’s much more reliable, flexible, time saving and usable than using sockets, pipes or using direct connections (like MySQL).
Hello.
It is of course up to you to make the risk assessment Adam. As long as there is no risk of doing any harm by turning your devices on or off, then you are good to go.
Another issue you should keep in mind, is that people sometimes probes ip-addresses for holes. Such probing might inadvertently trigger your device. I relalize that it also would take a little bit more than that, according to the packet format/protocol of your UDP-packets. But I think all that would be to it, would be high bits in the right places.
Now that would be funny wouldn’t it, to have such a lamp, to blink every time someone probed ones router?
Hello.
I referred to a C-project I am currently working on above. (The one that is described in the link in my signature).
I made it to work late sunday and it has worked since then. (Spent the weekend developing my developing environment for plain C.) If someone would find it useful I’d be very happy. And if someone finds something that errs with it even more happy. It is supposed to work with UTF-8 and localization, You can also search with Perl-regexp’s in it. It is here
Thanks for trying.