[Tutor] quick ?

2006-09-13 Thread dpotter
I am new to Python (and programming).  In teaching myself I wrote a
small program that will pick random lottery numbers, I want to check for
duplicates and rerun the random function.  But I am hitting a wall. 
This is what I think should work, but I still get duplicates.  TIA.



print "\n"
count = input("How many quick picks do you need? ")
print "\n"
num = 0
while count > 0:
   num1 = randint(1,55)
   num2 = randint(1,55)
   while  num2 == num1:
# looking for duplicates
  num2 = randint(1,55)
   num3 = randint(1,55)
   while num3 == (num1 or num2):   
# looking for duplicates
 num3 = randint(1,55)
   num4 = randint(1,55)
   while num4 == (num1 or num2 or num3):   
# looking for duplicates
 num4 = randint(1,55)
   num5 = randint(1,55)
   while num5 == (num1 or num2 or num3 or num4):   
# looking for duplicates
 num5 = randint(1,55)
   pb = randint(1,42)
   count = count - 1
   answer = [num1, num2, num3, num4, num5]
   answer.sort()
   num = num + 1
   print "#",num, answer, "and for the powerball:", pb
print "\n"

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Capture telnet output to a file?

2006-10-16 Thread dpotter
Hello,

I am trying to capture telnet output to a file.  For example I want to
telnet into a router and run the command “show arp” and be able to
capture all the arp information that normally would show up on the
screen to a file on my system.I am using python and pexpect to
backup my router configurations on a daily basis, but for this the
router has the option to send the configuration via tftp to a server,
there is no option to send normal screen data to a file.  Any ideas?

Thank you.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Capture telnet output to a file?

2006-10-16 Thread dpotter
I was not aware of script.  Thanks!

- Original Message -
From: Bill Campbell <[EMAIL PROTECTED]>
Date: Monday, October 16, 2006 1:55 pm
Subject: Re: [Tutor] Capture telnet output to a file?
To: tutor@python.org

> On Mon, Oct 16, 2006, [EMAIL PROTECTED] wrote:
> >Hello,
> >
> >I am trying to capture telnet output to a file.  For example I 
> want to
> >telnet into a router and run the command ?show arp? and be able to
> >capture all the arp information that normally would show up on the
> >screen to a file on my system.I am using python and pexpect to
> >backup my router configurations on a daily basis, but for this the
> >router has the option to send the configuration via tftp to a server,
> >there is no option to send normal screen data to a file.  Any ideas?
> 
> One could use the ``script'' program in *NIX systems which
> captures your entire session.
> 
> I haven't used pexpect with python yet, but the perl expect
> module can also be used to capture things like this, and I would
> expect that one could do this with pexpect as well.
> 
> Bill
> --
> INTERNET:   [EMAIL PROTECTED]  Bill Campbell; Celestial Software LLC
> URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
> FAX:(206) 232-9186  Mercer Island, WA 98040-0820; (206) 
> 236-1676
> 
> ``If the personal freedoms guaranteed by the Constitution inhibit the
> government's ability to govern the people, we should look to limit 
> thoseguarantees.''
>   -President Bill Clinton, August 12, 1993
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Capture telnet output to a file?

2006-10-16 Thread dpotter
That looks like it will do what I want.

Thank You!

- Original Message -
From: Kent Johnson <[EMAIL PROTECTED]>
Date: Monday, October 16, 2006 2:06 pm
Subject: Re: [Tutor] Capture telnet output to a file?
To: [EMAIL PROTECTED]
Cc: tutor@python.org

> [EMAIL PROTECTED] wrote:
> > Hello,
> > 
> > I am trying to capture telnet output to a file.  For example I 
> want to
> > telnet into a router and run the command “show arp” and be able to
> > capture all the arp information that normally would show up on the
> > screen to a file on my system.I am using python and pexpect to
> > backup my router configurations on a daily basis, but for this the
> > router has the option to send the configuration via tftp to a 
> server,> there is no option to send normal screen data to a file.  
> Any ideas?
> 
> You might be able to do this using telnetlib instead of pexpect.
> 
> Kent
> 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] passing a variable ?

2006-10-19 Thread dpotter
I am stumped.  I am trying to pass the variable 'savename' to a string
and get errors.  
can someone tell me why?  Thanks to all on this list.  (The problem
happens in the for loop 1st line)

This is my error
Traceback (most recent call last):
  File "./ArpAcl.py", line 39, in ?
fout = file('/home/cable/sandbox/%s', 'a''w' % savename)
TypeError: not all arguments converted during string formatting



import pexpect
import getpass
import sys

#Go through all the routers and gather Access-list or ARP information,
return the info into it's own file.
print '\n'
print 'Router scrub will take approx 60 Seconds.'
print '\n'
print "For the ARP list enter '1'"
print "For the ACL list enter '2'"
print '\n'

choice = input('Enter 1 or 2: ')
print '\n'
telpass = getpass.getpass('Please enter the telnet password: ')
enablepass = getpass.getpass('Please enter the enable password: ')

if choice == 1:
command = 'show arp'
savename = 'arp.txt'
else:
command = 'sh ip access-l'
savename = 'acl.txt'

print '\n'
print '-' * 48
print 'You will be notified when program is finished.'
print '-' * 48

x = open('/home/cable/router.list','r')
routers = x.readlines()

for i in routers:
fout = file('/home/cable/sandbox/%s', 'a''w' % savename)
c = pexpect.spawn('/usr/bin/telnet %s' %i)
c.expect('Please Enter Password:')
c.sendline(telpass +'\r')
c.sendline('enable\r')
c.expect('Password:')
c.sendline(enablepass + '\r')
c.expect('#')
c.logfile = fout
c.sendline('skip\r')
c.expect('#')
c.sendline(command + '\r')
c.expect('#')
fout.close()
c.close()
x.close()
print '\n'
print 'Finished!'
print '\n'
print 'File has been save to /home/cable/sandbox/%s' % savename
raw_input('Press any key to exit')

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor