Find my (R)Pi

March 17, 2014 at 8:42 pm (computers, internet, maker) (, , , )

I like tinkering with my Raspberry Pi, but I also tend to have them configured for remote SSH to save dragging out a keyboard and screen. I also use the small Edimax WiFi USB dongles, but I also just like to let the pi find its own address on the network using DHCP … so I often need to either hook up to my routers admin/status page to see what nodes it has found or just attempt to connect to a few nodes in the range I know will be used for the pi.

Eventually I got fed up with doing this, so instead I wrote a very simple perl script to use Net::Ping to scan a small range of addresses and report on which ones are responding, and then see if port 22 (SSH) or 80 (web) are open.  Then I know where my pi is.

Net::Ping can use the tcp for ping, which has the advantage that you don’t need privileges for the script to use icmp.  The disadvantage is that most things won’t respond to the tcp echo port.  Consequently, I use Net::Ping in two modes – first with icmp to see if the host is alive, then with tcp to probe the ports I’m interested in.  This does require it to be run with administrator privileges, but that is fine for me.

I don’t scan a whole range, that would take too long for this very simplistic case, so I just scan 20 or so addresses that I am interested in.

There are a wealth of network scanning and management applications out there, but this has the advantage of being very simple.  Just what I needed.  Below is the code.  Nothing exciting – about as simple as it gets, but it works. 

To run from Windows, I use a simple batch file to call the perl interpreter with the script, then pause afterwards (to give me a chance to read the output).  This can then be used by right-click -> run as administrator.


#!/usr/bin/perl -w
use Net::Ping;

my $subnet="192.168.0.";
my @ports = (22, 80);
my $timeout = 1;

my $p_icmp = Net::Ping->new ("icmp", $timeout) or die "Can't start icmp ping";
my $p_tcp = Net::Ping->new ("tcp", $timeout) or die "Can't start tcp ping";
for ($i = 50; $i<70; $i++) {
    my $host = $subnet.$i;
    print "$host: ";
    if ($p_icmp->ping ($host)) {
        print "ok ";
        foreach my $port (@ports) {
            if ($p_tcp->ping ($host)) {
                print "$port ";
        print "\n";
    } else {
        print "nok\n";

Permalink 1 Comment

Learn to code in one hour

March 3, 2014 at 10:08 pm (computers) (, , )

Apparently, today saw the official launch of the UK Hour of Code, something I am still making up my mind about. I’ve run through some of the exercises with the kids, and they seem moderately interested.  They haven’t asked to go back and try some more of the puzzles yet, so I guess its a bit too early to say.

It was certainly entertaining to use basic logo-like commands to move an angry bird around the screen and the videos of introduction by significant people in the coding world was good too.  I didn’t quite get the “show code” bit … for the most part, a series of function calls for moveForward(); turnLeft(); etc didn’t mean anything to them.  And the repeat block turns into a for loop with no explanation whatsoever, so that took some explaining on my part, but that was perhaps going a bit too far.

So did they learn to code as much of the media hype has been suggesting?  Not quite, but bringing it back to pragmatic reality did they gain an appreciation of some of the basic principles of coding?  Maybe.  They learnt the following:

  • Instructions go in sequence, get the sequence wrong and it sometimes matters a lot and other times not at all.
  • Computers only do exactly what you tell them to do, and no more, and especially are not very good at knowing what you mean.
  • You can repeat instructions
  • You can get the computer to work some things out for itself using tests.
  • Debugging can be frustrating and hard!

They had no appreciation of how computers count, how instructions are processed or what was actually in place to allow them to use a tablet computer to drag graphical blocks around the screen in order to make an angry bird move.

So, they learned some basic principles of programming (if and loops) but there is a very long way to go.  It will take a lot more than an hour I think.

And of course, one of the real challenges is that even for a very experienced coder it still takes a lot of acquired knowledge and time to write anything of any quality.  Especially when you see the polish of many free apps or web-based games (flappy bird not withstanding).

But maybe “game creating” systems is a good way to get started – get people creating something themselves, using frameworks, logic, graphics and so on available to them in such systems.  For something like that Scratch works very well, and you don’t all need a Raspberry Pi to use it, any handy PC will do.

So like all these things, the key will be in the follow-up – so maybe the idea of some computer science on the curriculum is a good thing.  I’m still undecided – coding isn’t really for everyone, but maybe everyone should try it a bit before deciding.

I guess the thing that I really find missing from all these things is the wonder, the marvel that is the “shoulders of giants” that all this sits on.  When I stop to think about what code is actually allowing my kids to drag a few boxes around on the screen to try out coding, it is quite a marvel:

On the device: javascript, running in the browser, using graphical frameworks to render HTML, delivered over HTTP, via the network stack running TCP/IP via drivers within the operating system for WiFi using all the resources of the processor, graphics, sound and network and reacting to input from the touch screen.

Over the network: WiFi to the broadband router – TCP/IP, DNS, ARP, DHCP and some Ethernet in there too between the Wifi AP and the actual Internet connection; then my router via routers in the ISP to get the connectivity to the Internet – negotiating a public IP, handling NAT, routing within their infrastructure and across Internet exchange points, exchange of routing information via peering agreements, etc, etc.

On the server: operating system, drivers, and so on again, this time probably virtualised; then some kind of LAMP stack or equivalent. Yes, netcraft tells me its running Linux on Amazon EC2, although this could be some kind of content delivery network of course.

Now it will be really great if the hour of code could get some of this magic across to people – quite how much code is running to allow the world we live in to function – it would be really good if someone could find a way to give them a flavour of quite how special it all is and how much combined work has gone into something we now all simply take for granted.


Permalink Leave a Comment