Category Archives: Python
How to do error handling in python: try: b=kjk except Exception as e: print(e) output: name ‘kjk’ is not defined name ‘b’ is not defined Advertisements
What is the difference between import and from x import y: With import x, you refer things in x like x.something. WIth from x import *, you refer things in x directly just as something.
Scapy have two versions: Scapy v1.x.: Works with Python 2.4 Scapy v2.x.: If Scapy v2 version is <= 2.3.3 it needs Python 2.5, If Scapy v2 version is > 2.3.3 needs Python 2.7. How to install scapy: 1> To install … Continue reading
Python version 3.6.2: Python is an interpreted language. Statement grouping is done by indentation instead of beginning and ending brackets. Note Output is in blue. Comments in python: Use hash to enter comment in python. # Indexing of string: name=”abcdef” … Continue reading
Prerequisite: You need to install openssl package for python. Use following command to install openssl for python: pip install pyopenssl #Following script will create a self signed root ca cert. from OpenSSL import crypto, SSL from os.path import join import … Continue reading
Consider the following xml file: <?xml version=”1.0″?> <config version=”6.1.0″ urldb=”paloaltonetworks”> <mgt-config> <users> <entry name=”admin”> <phash>********</phash> <permissions> <role-based> <superuser>yes</superuser> </role-based> </permissions> </entry> </users> </mgt-config> </config> Root of the above xml … Continue reading
Take telnet of a cisco router/switch and execute commands: import os import telnetlib host = “10.50.243.28” user = “username” password = “cisco” telnet = telnetlib.Telnet(host) telnet.read_until(‘Password: ‘, 3) telnet.write(password + ‘r’) telnet.write(‘enable’ + ‘rn’) telnet.write(‘cisco’ + ‘rn’) telnet.write(‘term len 0’ … Continue reading