Created
August 2, 2013 05:01
-
-
Save mmirabent/6137633 to your computer and use it in GitHub Desktop.
Perl script for telnet scraping IP addresses looking for Cisco IP Phones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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