Posting again because subject line is misleading. Sorry for the inconvenience CM > Hello all, > > I am writing a script that opens up a telnet session with a specific device, > and issues a command. > I would then like to look through each of the lines and look for the target > line by matching a pattern. > Once this is done, I would like to split the values and assign the to > variables. > > The thing is, that I took the output of the command "show dhcp client" and > copied it to a text file. > Then looked through the text search with the while. Find the pattern, split > and fill the variables. > It worked fine... > I cannot seem to get it to work with the telnet session. > I know that I could capture all of the text and write it to a filehandle, > then > search through that file, but I would prefer to skip that step. > > Any suggestions? > Script is below. > > #!/usr/bin/perl -w > > use IO::Socket; > use IO::File; > > $router = "143.137.50.210"; > > > print "Connecting to IP address $router\n"; > $remote = new IO::Socket::INET(PeerAddr=>$router, > PeerPort=>23, > Proto=>"tcp", > Type=>SOCK_STREAM) or die "Couldn't connect to IP address > $router\nSystem error: $!"; > > # output the address and the port we are connected to > print "Connection made to ", $remote->peerhost, "", "\n"; > > # set buffering off > $remote->autoflush(1); > > print $remote "\n\n"; > print $remote "show dhcp client\n"; > print $remote "quit\n"; > > while ($line = <$remote>){ > if ($line =~ m/^IP Address/){ > ($ipAddress, $ipValue) = split(/\s+:\s+/, $line); > #print $line; > print "The $ipAddress for your router is $ipValue"; > } > } > > close ($remote); > > > Thanks, > > Craig > [EMAIL PROTECTED] > Pager > Numeric: 1-877-895-3558 > Email pager: [EMAIL PROTECTED] > -------------------------------------------------------------- > You will never find time for anything. > If you want time, you must make it. > > Charles Buxton >