Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Perl script for telnet scraping IP addresses looking for Cisco IP Phones

View telnet_cisco.pl
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#
# telnet_cisco.pl
# Marcos Mirabent
#
# Scan for Cisco IP Phones given a .csv of IP addresses
#
# Created by Marcos Mirabent on 2013-07-18.
# Copyright 2013 Marcos Mirabent. All rights reserved.
#
 
# Use statements
use Net::Telnet ();
use Text::CSV_XS;
 
# Set up the csv importing
# Set up Telnet
my @phones;
my $csv = Text::CSV_XS->new;
open my $fh, "<", $ARGV[0] or die "cannot open\"".$ARGV[0]."\"!";
 
# set up telnet object and csv object. Drop the header line in the csv file
$t = new Net::Telnet ();
$t->prompt('/>/');
$t->timeout(5);
 
$csv->bind_columns(\$ip_addr, \$mac_addr);
$csv->getline ($fh);
 
# iterate through the csv file, extracting the ip address field
while ($csv->getline ($fh)) {
eval {
print "Trying ".$ip_addr."\n";
$t->open($ip_addr);
$t->waitfor('/Password/');
$t->print('cisco');
$t->waitfor('/>/');
@lines = $t->cmd('show config');
for $line (@lines) {
if ($line =~ m/Platform.*Phone/) {
print "Found matching IP Phone"."\n";
push @phones,"Phone ".$ip_addr." ".$mac_addr."\n";
}
}
}; warn $ip if $@;
}
 
for $phone (@phones) {
print $phone;
}
 
close $fh;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.