Re: [Tutor] Telnet to cisco device

2006-02-27 Thread Hugo González Monteverde
Hi Gideon,

Seems that you're looking for some prompts, but are you sure they are 
presented as such from the server? For example, your password prompt has 
a space after the colon:

> tn.read_until('Password: ') #expected prompt after putting in the username

Have you tested what you are supposed to be getting  with the 
read_some(1) method??? Try that first, and check that the information 
you expect is actually the one you should be getting from the server.

Hope that gets you on te way to troubleshoot it.

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


[Tutor] Telnet to cisco device

2006-02-27 Thread STREET Gideon (SPARQ)
Title: Telnet to cisco device






Hi all,


I'm trying to get a script together to automate adding a couple of commands across a lot of cisco switches.  Thought I'd try to get the script working correctly on one switch first.  I've been reading a few online tutorials and have managed to kludge up the following (which fails where commented).  Anyone able to advise where I may be going wrong?

I'm sitting on a windows box here at work, otherwise I'd see what I could get expect to do.


Thanks


Gideon




import getpass

import sys

import telnetlib


HOST = 'switch_name'  # this is the hostname for device, to be changed to read from file when figure that out

user = raw_input('Username: ')

password = getpass.getpass()


tn = telnetlib.Telnet(HOST) #make less typing for me


tn.read_until('Username: ') #expected prompt after telnetting to the router

tn.write(user + '\r\n')  #hopefully write username and pass character return


raw_input('ENTER to continue') # just to see if it makes this far


# this is where the program appears to hang


tn.read_until('Password: ') #expected prompt after putting in the username

tn.write(password + '\r\n')



tn.read_until(HOST + ">") #expected prompt is "hostname>"

tn.write('enable \n') # go to exec mode


tn.read_until('Password: ') #prompt to go to exec mode

tn.write(password + '\n')



tn.read_until(HOST + '#')  #this should be the prompt after enable "hostname#"

tn.write('sh int status' '\r\n') #run this command, read this from file when i figure out how


tn.read_until(HOST + '#') #prompt once above command has finished running, useful when reading multiple commands


tn.write('exit' '\R\N') #disconnect from the session


print tn.read_all() #prints out something, maybe needs to be prior to "exit" command


tn.close()

  




This e-mail (including any attachments) may contain confidential or
privileged information and is intended for the sole use of the person(s) to
whom it is addressed. If you are not the intended recipient, or the person
responsible for delivering this message to the intended recipient, please
notify the sender of the message or send an e-mail to
mailto:[EMAIL PROTECTED] immediately, and delete all copies. Any
unauthorised review, use, alteration, disclosure or distribution of this
e-mail by an unintended recipient is prohibited. Ergon Energy accepts no
responsibility for the content of any e-mail sent by an employee which is of
a personal nature.

Ergon Energy Corporation Limited  ABN 50 087 646 062
Ergon Energy Pty Ltd  ABN 66 078 875 902
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New Tutorial topic available

2006-02-27 Thread ->Terry<-
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1


Yesterday (Feb 26, 2006) at 9:04pm, Mark Thomas spoke these wise words:

- ->On 2/26/06, Alan Gauld <[EMAIL PROTECTED]> wrote:
- ->> I've just uploaded the latest tutorial topic covering inter-process
- ->> communications. It covers pipes and the use of fork().
- ->>
- ->> Enjoy, as ever feedback is welcomed.

- ->Thanks Alan, your pages are a great source of information for us newbies.

I agree completely. Thank you Alan!

- -- 
Terry

 ,-~~-.___.   Terry Randall 
/ |  ' \  http://members.socket.net/~tvbare/index.html
   <   )0
\_/, ,-'
     //   Linux Counter Project User# 98233
  /  \-'~;/~~~(0)
 /  __/~|   /  |If only Snoopy had Slackware!
   =( __| (|

"He is your friend, your partner, your defender, your dog.
You are his life, his love, his leader. He will be yours,
faithful and true, to the last beat of his heart. You owe
it to him to be worthy of such devotion."-- Unknown

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.7 (GNU/Linux)

iD8DBQFEA7j2QvSnsfFzkV0RArHtAJ49RVEsvX1fQtcKKdscX7u6dg+mswCfeoNI
djWhL1luQtImcmoTloiDNMQ=
=25cA
-END PGP SIGNATURE-

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


Re: [Tutor] Converting MAC address . Need Help

2006-02-27 Thread Travis Spencer
On 2/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> This is not what Sudarshana asked for - '\\x00' and '\x00' are not the
> same string

Thanks for clearning that up for me, Kent.

--

Regards,

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


Re: [Tutor] Converting MAC address . Need Help

2006-02-27 Thread Kent Johnson
Travis Spencer wrote:
> On 2/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> 
>>Sudarshana KS wrote:
>>
>>>The problem i am facing is the mac address i have is in the form
>>>00:11:22:33:44:55 need to convert to '\x00\x11\x22\x33\x44\x55'
> 
> 
> Perhaps I'm mistaking but it seems that you need to prepend the `\x'
> escape sequence to the mac address you already have and replace the
> colons with the same sequence.  If it is any harder than that, I'm
> missing something.  If I got what you mean, Sudarshana, you can
> achieve your goal with this one-liner:
> 
> 
macAddress = '00:11:22:33:44:55'
reduce(lambda a, b: a + r"\x" + b, macAddress.split(':'), "")
> 
> '\\x00\\x11\\x22\\x33\\x44\\x55'

This is not what Sudarshana asked for - '\\x00' and '\x00' are not the 
same string - the first is a string of four characters - backslash, 
letter x, digit 0, digit 0. The second is a string of one character with 
the character value 0 - a NUL. Sudarshana wants to make a string of byte 
values, you make a string of character representations of byte values. 
Very different.

>>The list elements are still strings, you need to convert them to
>>integers.
> 
> Why is this needed, Kent?  Why not just leave them as strings?

Because he wants byte values not strings.
> 
> 
>>The strings are in hexadecimal so use the optional base
>>parameter to int():
>>  >>> int('11', 16)
>>17
>>
>>Finally you have to convert this number to a byte of a string using chr():
>>  >>> chr(17)
>>'\x11'
> 
> Seems like a lot of extra work to me.

It all depends on where you want to end up :-)
There is actually a one-liner to do this but I didn't want to give it 
all away.

Kent


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


Re: [Tutor] Converting MAC address . Need Help

2006-02-27 Thread Travis Spencer
On 2/27/06, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Sudarshana KS wrote:
> > The problem i am facing is the mac address i have is in the form
> > 00:11:22:33:44:55 need to convert to '\x00\x11\x22\x33\x44\x55'

Perhaps I'm mistaking but it seems that you need to prepend the `\x'
escape sequence to the mac address you already have and replace the
colons with the same sequence.  If it is any harder than that, I'm
missing something.  If I got what you mean, Sudarshana, you can
achieve your goal with this one-liner:

>>> macAddress = '00:11:22:33:44:55'
>>> reduce(lambda a, b: a + r"\x" + b, macAddress.split(':'), "")
'\\x00\\x11\\x22\\x33\\x44\\x55'

Perhaps you may prefer this:

>>> "\\x" + macAddress.replace(":", "\\x")
'\\x00\\x11\\x22\\x33\\x44\\x55'

> The list elements are still strings, you need to convert them to
> integers.

Why is this needed, Kent?  Why not just leave them as strings?

> The strings are in hexadecimal so use the optional base
> parameter to int():
>   >>> int('11', 16)
> 17
>
> Finally you have to convert this number to a byte of a string using chr():
>   >>> chr(17)
> '\x11'

Seems like a lot of extra work to me.

--

Regards,

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


Re: [Tutor] RDT server for excel

2006-02-27 Thread Danny Yoo


On Mon, 27 Feb 2006, [ISO-8859-1] J�nos Juh�sz wrote:

> I would like to make a small RDT Server as COM Server in python that can
> be called from excel as =RDT("StockBalance.MyServer",,"17") I'v
> tried to use google, but with not too much success. I just would like a
> simple sample.

Hi Janos,

Unfortunately, I'm not sure if we can be of much help, since this is very
Windows specific.  You might want to ask about this on the win32 list; the
folks there have more expertise on writing COM servers, and I'm sure they
can give a few pointers.  Here's a link to their mailing list:

http://mail.python.org/mailman/listinfo/python-win32

Best of wishes to you!

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


Re: [Tutor] RDT server for excel

2006-02-27 Thread Bob Gailer
János Juhász wrote:
> Hi All,
>
> I would like to make a small RDT Server as COM Server in python that can be
> called from excel as =RDT("StockBalance.MyServer",,"17")
>   
I for one have no idea what RDT is, so can't help. Maybe someone else 
has an idea. Or can you give us more information or a link about RDT?
[snip]
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] RDT server for excel

2006-02-27 Thread János Juhász
Hi All,

I would like to make a small RDT Server as COM Server in python that can be
called from excel as =RDT("StockBalance.MyServer",,"17")
I'v tried to use google, but with not too much success.
I just would like a simple sample.


Yours sincerely,
__
János Juhász

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


Re: [Tutor] Converting MAC address . Need Help

2006-02-27 Thread Kent Johnson
Sudarshana KS wrote:
> 
> Hi,
> 
> I am using scapy for writing a dhcp client.
> 
> The problem i am facing is the mac address i have is in the form 
> 00:11:22:33:44:55 need to convert to '\x00\x11\x22\x33\x44\x55'
> Please help me out with this problem. The chaddr field in dhcp ( SCAPY) 
> requires '\x00\x11\x22\x33\x44\x55'  format.

If you break this down into smaller pieces it is not so hard.

Use the split() method of a string to break it into a list of substrings:
  >>> mac = '00:11:22:33:44:55'
  >>> mac.split(':')
['00', '11', '22', '33', '44', '55']

The list elements are still strings, you need to convert them to 
integers. The strings are in hexadecimal so use the optional base 
parameter to int():
  >>> int('11', 16)
17

Finally you have to convert this number to a byte of a string using chr():
  >>> chr(17)
'\x11'

I'll leave it to you to put all the pieces together. The join() method 
may be helpful as a last step, it converts a list of strings to a single 
string:

  >>> ''.join(['a', 'b', 'c'])
'abc'

Kent

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


[Tutor] Converting MAC address . Need Help

2006-02-27 Thread Sudarshana KS
Hi,

I am using scapy for writing a dhcp client. 

The problem i am facing is the mac address i have is in the form
00:11:22:33:44:55 need to convert to '\x00\x11\x22\x33\x44\x55' 
Please help me out with this problem. The chaddr field in dhcp ( SCAPY) requires '\x00\x11\x22\x33\x44\x55'  format. 

I want this to be assinged through variables. Please let me know if this i doable.

Thanks in advance,Sudarshana K S
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Finding items in a list

2006-02-27 Thread Hugo González Monteverde
As others have said, a concrete example would be great. For the time 
being, sounds like maybe regular expressions could do it. We don't know 
if your data is already in a list of small strings, or if it is just a 
huge string.

Take a look here for an intro to RE, though:

http://www.amk.ca/python/howto/regex/

Try to send a bit more specifics, we'll be here...

Hugo

Emily Patek wrote:
> Hi - 
> I am trying to break apart a list into several smaller lists based on 
> repeating nearly identical entries.  For example, every so often there is the 
> word CLUSTER with a number after it, like CLUSTER 1.  I can find them one by 
> one, but would like to
> do a while loop for while item in list = CLUSTER X.  Is there a key that I 
> can put in that means "any text that comes after" that would go from cluster 
> to cluster without my typing in each cluster and number?  I am a very 
> beginner programmer and am
> trying to parse a file of gene-related information that is in a not-so-easy 
> format.  I put it into a list based on lines through the splitlines() method. 
>  I also thought about splitting the text by CLUSTER and then making each item 
> of the list into
> a string that I could then split, but couldn't get that to work either...
> 
> Thanks! 
> Emily
> 
> ___
> 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] list packing

2006-02-27 Thread Kent Johnson
kevin parks wrote:
> John,
> 
> Thanks... i am liking this variation a tad more since it means i only
> have to type the path in one place  but it is akin to your second
> one... i was (still am really) having a hard time understanding
> how to apply path.join _and_ listdir  sometimes list comprehensions
> twist my brain but this one is worth studying ...
> 
> nice! two little lines that do a boatload of work! hee hee
> 
> 
> pth = '/Users/kpp9c/snd/01'
> samples = [os.path.join(pth, f) for f in os.listdir(pth) if f.endswith 
> ('.aif')]
> 
> 
> i could even add:
> samples = [os.path.join(pth, f) for f in os.listdir(pth) if f.endswith 
> ('.aif' & f.startswith('t')]

You might like Jason Orendorff's path module. Using it you can write
import path
pth = path.path('/Users/kpp9c/snd/01')
samples = list(pth.walkfiles('t*.aif'))

path.walkfiles() returns an iterator, that is why the list() call is 
needed. If you are going to loop over the samples you can omit it:
   for sample in pth.walkfiles('t*.aif'):
 ...

http://www.jorendorff.com/articles/python/path/index.html

Kent

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


Re: [Tutor] list packing

2006-02-27 Thread Kent Johnson
Sean Perry wrote:
> os.path.join() is self-documenting. I find this to be a better reason to 
> use it than anything else. But then my code only ever runs on Unix of 
> some flavor.

I'm not sure why you put in the comment about Unix - os.path.join() is 
the recommended way of joining paths portably - it will do the right 
thing on any supported platform.

Kent

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


Re: [Tutor] list packing

2006-02-27 Thread kevin parks
John,

Thanks... i am liking this variation a tad more since it means i only
have to type the path in one place  but it is akin to your second
one... i was (still am really) having a hard time understanding
how to apply path.join _and_ listdir  sometimes list comprehensions
twist my brain but this one is worth studying ...

nice! two little lines that do a boatload of work! hee hee


pth = '/Users/kpp9c/snd/01'
samples = [os.path.join(pth, f) for f in os.listdir(pth) if f.endswith 
('.aif')]


i could even add:
samples = [os.path.join(pth, f) for f in os.listdir(pth) if f.endswith 
('.aif' & f.startswith('t')]

to make sublists in guess

What i like about this is that i can chance my directory structure  
(add/delete/rename/etc)
and shape it any way that i want and then Python reflects all my  
restructuring... lovely...
Exactly the type of tedious thing i want Python to do for me *^-^*

cheers,

kevin



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