Popular recipes by Tim Keating http://code.activestate.com/recipes/users/131643/2002-09-25T19:47:17-07:00ActiveState Code RecipesSimple telnet session scripting (Python)
2002-09-25T19:47:17-07:00Tim Keatinghttp://code.activestate.com/recipes/users/131643/http://code.activestate.com/recipes/152043-simple-telnet-session-scripting/
<p style="color: grey">
Python
recipe 152043
by <a href="/recipes/users/131643/">Tim Keating</a>
(<a href="/recipes/tags/network/">network</a>).
Revision 2.
</p>
<p>This is an EXTREMELY simple module for scripting a telnet session. It uses abbreviated versions of the commands exported by telnetlib followed by any necessary arguments.</p>
<p>An example of use would be:</p>
<p>import telnetscript</p>
<p>script = """ru Login:
w %(user)s
ru Password:
w %(pwd)s
w cd ~/interestingDir
w ls -l
ra
w exit
c
"""</p>
<p>user = 'foo'
pwd = 'bar'
conn = telnetscript.telnetscript( 'myserver', vars() )
lines = conn.RunScript( script.split( '\n' ))</p>
<p>This assigns lines the value of the output of "ls" in "~/interestingDir" for user foo on myserver.</p>
Format version numbers (Python)
2002-02-04T14:09:35-08:00Tim Keatinghttp://code.activestate.com/recipes/users/131643/http://code.activestate.com/recipes/111971-format-version-numbers/
<p style="color: grey">
Python
recipe 111971
by <a href="/recipes/users/131643/">Tim Keating</a>
.
</p>
<p>It is common for Python modules to export their version number in list or tuple form. While it is simple to convert a dot-delimited string to a tuple, it's subtle and tricky to go the other way, particularly when you don't know how many "digits" there are. This recipe includes a pair of functions that convert between forms. Also handy for IP addresses!</p>
Rolling dice (Python)
2001-09-19T13:05:10-07:00Tim Keatinghttp://code.activestate.com/recipes/users/131643/http://code.activestate.com/recipes/68422-rolling-dice/
<p style="color: grey">
Python
recipe 68422
by <a href="/recipes/users/131643/">Tim Keating</a>
.
</p>
<p>A simple function to permit you to generate random numbers by emulating a dice roll. The number of dice and the number of sides to each die are the parameters of the function. In order to (for example) roll 4d6, you would call dice( 4, 6 ).</p>