Skip to content

Instantly share code, notes, and snippets.

@andysc
Last active June 6, 2020 18:11
Show Gist options
  • Save andysc/5605183 to your computer and use it in GitHub Desktop.
Save andysc/5605183 to your computer and use it in GitHub Desktop.
Speak the IP address of your linux machine. Perfect for Raspberry PIs or other headless servers with audio output. Just plug in a speaker or earphones and wait to be told the IP address to ssh to!
Speak the IP address of your linux machine.
Perfect for Raspberry PIs or other headless servers. Just plug in a speaker or earphones and wait to be told the IP address to ssh to!
Requires "espeak" - sudo apt-get install espeak
Make IPspeak.pl executable:
chmod +x IPspeak.pl
Run it automatically at startup (otherwise it's rather pointless, as you'd have to know the IP address to log-in to start it ;) )...
Add to /etc/rc.local (e.g. sudo vi /etc/rc.local ) above the "exit 0", the line:
su -l pi -c 'nohup ./IPspeak.pl >> /dev/null &'
(note the spaces)
If you want to stop IPspeak (once you've logged in to the IP address it's told you), type:
pkill IPspeak
#!/usr/bin/perl
# IPspeak
# Andy S-C
# 18-May-13
# 15-Oct-16 - made more "human" ... ten dot nought dot one nine three dot seventeen
# this is the order we check the interfaces
@interfaces = ("eth0", "wlan0");
%names = ("eth0"=>"ethernet",
"wlan0"=>"wireless");
# give it a chance to get an IP address at boot-up
sleep 10;
while (1)
{
$found = 0;
for $interface (@interfaces)
{
print "$interface -> $names{$interface}\n";
$IP = `ifconfig $interface | grep 'inet addr'`;
$text = $names{$interface} . " address ";
if ($IP =~ /inet addr:(.*?) /)
{
$IP = $1;
$text .= &render_address($IP);
&speak($text);
$found=1;
}
}
if (!$found)
{
$text = "no IP address";
&speak($text);
}
sleep 30;
}
sub speak
{
my ($text) = @_;
print "'$text'\n";
system("espeak -s150 '$text'");
}
sub render_address
{
my ($IP) = @_;
my @octets = split(/\./,$IP);
my @address;
foreach $octet (@octets)
{
push(@address, &render_octet($octet));
}
my $text = join(" dot ",@address);
return $text;
}
sub render_octet
{
my ($number) = @_;
if ($number == 0)
{
$result = "nought";
}
elsif ($number < 100)
{
$result = $number;
}
else
{
# split into digits
$result = join(" ", split(//,$number));
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment