The time now is 09/10/08 - 23:31
Log in: Username: Password:
Search forums for:
  

complex programming help NWS b*****s

Post new topic   Reply to topic
Author Message
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 19:04    Post subject: complex programming help NWS b*****s Reply with quote

Hey guys .. hopefully someone can help.

I have a list of IP addresses that I need to telnet to and run a series of commands on. Which in and of itself is pretty simple but I have a few curves to throw into it.

There are multiple ways that the telnet session could respond: (ie it may just ask for a password and some may ask for a username and password).

So my question is this:
Is there a way say in perl to initiate a connection scrape what the prompt is, hold it in a buffer then iterate over a series of if statements until a match is made then execute a series of commands (after initiating a second telnet session)


Last edited by gotissues68 on 10/11/05 - 22:25; edited 1 time in total
Back to top
kireol
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 02 Aug 2003
Posts: 9517
Location: Royal Oak, MI



PostPosted: 10/10/05 - 19:09    Post subject: Reply with quote

almost positive PHP CURL can handle it np

http://us2.php.net/manual/en/ref.curl.php
Back to top
sinrakin
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 11 Oct 2002
Posts: 7044



PostPosted: 10/10/05 - 19:13    Post subject: Reply with quote

My first thought would be to do it with Expect (which I think runs on top of Perl but I don't even remember anymore). I'd have to look it up though.
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 19:18    Post subject: Reply with quote

yea expect is the ticket. I have the expect perl module installed on my dev machine .. being able to write out the sub routines to run based on the prompt isn't a problem I don't think Embarassed I just need to figure out if expect can handle iterations..

Let say I have something like

expect "Login:"

but receive "Username:" instead can it break from what its expecting and shift and run a sub routine based on what it got back or better yet can it determine which routine to run based on what it gets versus what it expects?
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 19:20    Post subject: Reply with quote

kireol wrote:
almost positive PHP CURL can handle it np

http://us2.php.net/manual/en/ref.curl.php


oh shitz this just may work Razz

make a request, store the request as a variable and then do if tests until a match is found
Back to top
kireol
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 02 Aug 2003
Posts: 9517
Location: Royal Oak, MI



PostPosted: 10/10/05 - 19:25    Post subject: Reply with quote

yup. which is pretty much what I PMd you about the other day. but was working with web pages, not telnets. it's real ez. all returned data is stored in a variable that you can search on and shit.
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 19:27    Post subject: Reply with quote

kireol wrote:
yup. which is pretty much what I PMd you about the other day. but was working with web pages, not telnets. it's real ez. all returned data is stored in a variable that you can search on and shit.


I am going to so be bugging you tonight :-p
Back to top
kireol
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 02 Aug 2003
Posts: 9517
Location: Royal Oak, MI



PostPosted: 10/10/05 - 19:33    Post subject: Reply with quote

heheh. it's just paybacks, that's all
Back to top
kireol
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 02 Aug 2003
Posts: 9517
Location: Royal Oak, MI



PostPosted: 10/10/05 - 19:47    Post subject: Reply with quote

actually after doing some reading, if your are telnetting, you may want to try PERLs $net::telnet
Back to top
kireol
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 02 Aug 2003
Posts: 9517
Location: Royal Oak, MI



PostPosted: 10/10/05 - 19:55    Post subject: Reply with quote

or phps stream_socket_client

that will do it for shizzle.


www.php.net/stream_socket_client
Back to top
lotek
RealPoor Sensei
RealPoor Sensei


Joined: 12 Oct 2002
Posts: 1598



PostPosted: 10/10/05 - 20:14    Post subject: Reply with quote

I'd do it with the perl expect route. Its real easy to use. few group.google searches and I had what I needed.

I used it to automate the generation of random assembly tests to run on a dev board. xmodem baby! ya!
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 20:19    Post subject: Reply with quote

lotek wrote:
I'd do it with the perl expect route. Its real easy to use. few group.google searches and I had what I needed.

I used it to automate the generation of random assembly tests to run on a dev board. xmodem baby! ya!


I think perl would be cleaner and I wouldn't get laughed at as much heh. I'll try some group searches tonight. As long as I can grab the data and store it then act upon that I should be good to go.
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 21:19    Post subject: Reply with quote

Alright well for some reason the perl gods are being nice to me tonight here's what I have so far that works...


#!/usr/bin/perl -w

use Net::Telnet;
@array = `cat blacklist.master`;
my $array_element;
foreach $array_element(@array)
{
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'return');
$telnet->open('$array_element');
$telnet->waitfor('/Login: $/i');
$telnet->print('<password>');
$telnet->waitfor('/# $/i');
$telnet->print('rem ipf insert 0 input drop -p udp -da $array_element -dp 53 internet');
$output = $telnet->waitfor('/# $/i');
print "successfully patched $array_element";
}


Now with the Errormode set to "return" it acts as if all of the IP's in the list where successfully reached when I know for a fact they were, if I set Errormode to "die" then the script dies when it can't contact the first dead IP, I have been browsing the docs and can't find anything like a "continue" mode where if it where to be "dead" so to speak that it would print to stdout and continue .... Also I have one prompt defined, how can I tell the script to look at each prompt and run commands based on what the prompt is showing?
Back to top
lotek
RealPoor Sensei
RealPoor Sensei


Joined: 12 Oct 2002
Posts: 1598



PostPosted: 10/10/05 - 21:28    Post subject: Reply with quote

gotissues68 wrote:
Alright well for some reason the perl gods are being nice to me tonight here's what I have so far that works...


#!/usr/bin/perl -w

use Net::Telnet;
@array = `cat blacklist.master`;
my $array_element;
foreach $array_element(@array)
{
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'return');
$telnet->open('$array_element');
$telnet->waitfor('/Login: $/i');
$telnet->print('<password>');
$telnet->waitfor('/# $/i');
$telnet->print('rem ipf insert 0 input drop -p udp -da $array_element -dp 53 internet');
$output = $telnet->waitfor('/# $/i');
print "successfully patched $array_element";
}


Now with the Errormode set to "return" it acts as if all of the IP's in the list where successfully reached when I know for a fact they were, if I set Errormode to "die" then the script dies when it can't contact the first dead IP, I have been browsing the docs and can't find anything like a "continue" mode where if it where to be "dead" so to speak that it would print to stdout and continue .... Also I have one prompt defined, how can I tell the script to look at each prompt and run commands based on what the prompt is showing?


you could setup a file that contains your call/resonpse pairs. read thoes into a hash and itterate through the hash comparing what you expect the call to be against what the telnet session gave. If a match, send the responce. one of a million ways.
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/10/05 - 21:59    Post subject: Reply with quote

lotek wrote:
gotissues68 wrote:
Alright well for some reason the perl gods are being nice to me tonight here's what I have so far that works...


#!/usr/bin/perl -w

use Net::Telnet;
@array = `cat blacklist.master`;
my $array_element;
foreach $array_element(@array)
{
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'return');
$telnet->open('$array_element');
$telnet->waitfor('/Login: $/i');
$telnet->print('<password>');
$telnet->waitfor('/# $/i');
$telnet->print('rem ipf insert 0 input drop -p udp -da $array_element -dp 53 internet');
$output = $telnet->waitfor('/# $/i');
print "successfully patched $array_element";
}


Now with the Errormode set to "return" it acts as if all of the IP's in the list where successfully reached when I know for a fact they were, if I set Errormode to "die" then the script dies when it can't contact the first dead IP, I have been browsing the docs and can't find anything like a "continue" mode where if it where to be "dead" so to speak that it would print to stdout and continue .... Also I have one prompt defined, how can I tell the script to look at each prompt and run commands based on what the prompt is showing?


you could setup a file that contains your call/resonpse pairs. read thoes into a hash and itterate through the hash comparing what you expect the call to be against what the telnet session gave. If a match, send the responce. one of a million ways.


thanks again lotek, this stuff really helps. I'd much rather have people point me in the right direction rather then doing it for me, thats the last thing I want =) thanks for the helpful hints....


as a side note this is for the "shady employer" who I leave at the end of the week, kinda of my final "ha I'm the better person in all of this" heh
Back to top
lotek
RealPoor Sensei
RealPoor Sensei


Joined: 12 Oct 2002
Posts: 1598



PostPosted: 10/10/05 - 22:53    Post subject: Reply with quote

gotissues68 wrote:
lotek wrote:
gotissues68 wrote:
Alright well for some reason the perl gods are being nice to me tonight here's what I have so far that works...


#!/usr/bin/perl -w

use Net::Telnet;
@array = `cat blacklist.master`;
my $array_element;
foreach $array_element(@array)
{
$telnet = new Net::Telnet ( Timeout=>10,
Errmode=>'return');
$telnet->open('$array_element');
$telnet->waitfor('/Login: $/i');
$telnet->print('<password>');
$telnet->waitfor('/# $/i');
$telnet->print('rem ipf insert 0 input drop -p udp -da $array_element -dp 53 internet');
$output = $telnet->waitfor('/# $/i');
print "successfully patched $array_element";
}


Now with the Errormode set to "return" it acts as if all of the IP's in the list where successfully reached when I know for a fact they were, if I set Errormode to "die" then the script dies when it can't contact the first dead IP, I have been browsing the docs and can't find anything like a "continue" mode where if it where to be "dead" so to speak that it would print to stdout and continue .... Also I have one prompt defined, how can I tell the script to look at each prompt and run commands based on what the prompt is showing?


you could setup a file that contains your call/resonpse pairs. read thoes into a hash and itterate through the hash comparing what you expect the call to be against what the telnet session gave. If a match, send the responce. one of a million ways.


thanks again lotek, this stuff really helps. I'd much rather have people point me in the right direction rather then doing it for me, thats the last thing I want =) thanks for the helpful hints....



no problems man. Glad to help.
Back to top
Occulis
RealPoor Jedi
RealPoor Jedi


Joined: 11 Oct 2002
Posts: 13293
Location: Moral Relativity Central



PostPosted: 10/10/05 - 23:23    Post subject: Reply with quote

so anyway like i was saying. burger s***s.
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/11/05 - 00:09    Post subject: Reply with quote

Occulis wrote:
so anyway like i was saying. burger s***s.


hahahah I was thinking to myself "Gee I wonder when Dunn is going to login and tell me I'm a poor coder and this is a piece of shit script and I should go die" ...

I love you Jason Embarassed
Back to top
Gethy
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 11 Oct 2002
Posts: 5595
Location: Tallahassee, FL



PostPosted: 10/11/05 - 00:46    Post subject: Reply with quote

needs more nws or ANGRE
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/11/05 - 18:30    Post subject: Reply with quote

Can someone review this

http://www.techiekb.com/routerfix-test.txt

And read my comments and see what the f**k I'm doing wrong....
Back to top
lotek
RealPoor Sensei
RealPoor Sensei


Joined: 12 Oct 2002
Posts: 1598



PostPosted: 10/11/05 - 18:52    Post subject: Reply with quote

gotissues68 wrote:
Can someone review this

http://www.techiekb.com/routerfix-test.txt

And read my comments and see what the f**k I'm doing wrong....


havent run it, but my guess would be that if array_element doesnt work, but setting ip does, your cat is adding the newline to the ip.
try adding
chop($array_element);
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/11/05 - 19:23    Post subject: Reply with quote

lotek wrote:
gotissues68 wrote:
Can someone review this

http://www.techiekb.com/routerfix-test.txt

And read my comments and see what the f**k I'm doing wrong....


havent run it, but my guess would be that if array_element doesnt work, but setting ip does, your cat is adding the newline to the ip.
try adding
chop($array_element);


LOL yea I had some review it as well and thats exactly what it was.. I really appreciate the help...

Not that anyone cares but I'm fixing a bug on about 7500 routers... that we shipped to customers! thanks to f*****g Efficient Networks/Siemens heh.
Back to top
motherface
RealPoor Guru
RealPoor Guru


Joined: 12 Mar 2003
Posts: 3407



PostPosted: 10/11/05 - 20:09    Post subject: Reply with quote

gotissues68 wrote:
as a side note this is for the "shady employer" who I leave at the end of the week, kinda of my final "ha I'm the better person in all of this" heh


Don't you mean kireol & Realpoor are "the better person" since they're the ones who solved it for you?

Edit: Misread your intent, I thought you were like gloating about being a super programmer. Yay!
Back to top
gotissues68
RealPoor Sensei
RealPoor Sensei


Joined: 21 Aug 2003
Posts: 1866



PostPosted: 10/11/05 - 22:22    Post subject: Reply with quote

motherface wrote:
gotissues68 wrote:
as a side note this is for the "shady employer" who I leave at the end of the week, kinda of my final "ha I'm the better person in all of this" heh


Don't you mean kireol & Realpoor are "the better person" since they're the ones who solved it for you?

Edit: Misread your intent, I thought you were like gloating about being a super programmer. Yay!


I would never gloat about being a super programmer since I'm not even close to being one. Kireol and Lotek helped me out by pointing me in the right direction, unless I misread something neither of them wrote it for me or gave me a solution, Lotek did provide an answer to a question I had though which I sincerly appreciate since I'm a perl virgin.

Time to NWS this b***h


Back to top
kireol
RealPoor Master of Posts
RealPoor Master of Posts


Joined: 02 Aug 2003
Posts: 9517
Location: Royal Oak, MI



PostPosted: 10/11/05 - 23:07    Post subject: Reply with quote

so hawt
Back to top
Display posts from previous:   
Post new topic   Reply to topic
Page 1 of 1

Related topics:
Eve Online Complex Exploits
Age of Conan is not complex and non-linear
Eve Online Hidden complex
Eve Online: Deadspace complexes
So the apt complex won't shovel after 8 inches and counting.
Complex locations in Eve Online
Farming complexes in Eve Online
Eve Online Complex respawn?
Is Vanguard too complex?
Will Pirates Of The Burning Sea be a complex mmorpg?
Ghost in the Shell: Standalone Complex
Anarchy Online Is Complex Game
Any Computer Programming majors here?
Beginning Programming
Need a little help with programming something
Fun programming task
Programming help
programming question
Marrying cousins, these sick sons of bitches
Come to the new server bitches
Librarians are bitches
WTF Women. You're not allowed to be bitches if it's free!
Entertain me, bitches!
WHAT UP BITCHES - NWS
The bitches love me
Ralph's two bitches
Suck it, bitches!
Science explains why women are bitches to eachother!
For anyone who still bitches about not having a mic
Strait Edge "Posi-Youth" Bitches.
Rap bitches
Later Bitches =)
Sup Bitches
Sons of bitches! Fix it!
my kind of bitches
Sup bitches
Slaping those Bitches
Hey you fanboy bitches... yeah fuck you...