Tweets of @pyliners
Neat little Python recipes in under 140 characters
- URL encode a string in Python
- Diff two directories
- Get ASN details for an IP address
- Covert a string to ROT13
- Display list of all the users on Unix-like systems
- Decode base64
- Encode a string to base64
- Print a calender
- Print the platform details
- Minimal HTTP server Python3.x
- Minimal HTTP server Python2.x
- Print zen of Python
- Import antigravity
- Print "Hello, world!"
python -c "import urllib; print urllib.quote_plus('string_of_characters_like_these:$#@=?%^Q^$')"
- Diff two directories
- Prints the contents that are unique to each directory
python -m filecmp dir1 dir2
- Handy during information gathering in a pentest
echo 8.8.8.8 | python -c "import urllib,json,sys;print json.load(urllib.urlopen('https://api.iptoasn.com/v1/as/ip/'+sys.stdin.read()))['as_number']"
curl -s http://ip-api.com/json/8.8.8.8 | python -c 'import sys, json; print json.load(sys.stdin)["as"]'
- ROT13 is a substitution cipher, it's fairly common to see ROT13 strings as part of CTF challenges
python -m encodings.rot_13 <<< "Sample string"
- Requires read access to
/etc/passwd
file
python -c "print '\n'.join(line.split(':',1)[0] for line in open('/etc/passwd'))"
- Decode base64 encoded string
- Comes handy during pentests/CTFs
python -m base64 -d <<< "dGhpcyBpcyBlbmNvZGVkCg=="
- Encode a string to base64
- Comes handy during pentests/CTFs
python -m base64 <<< 'apple'
- Prints a calender
python -m calendar
- Prints the underlying platform details
platform
module is OS agnostic.
python -m platform
- Minimal HTTP server in Python 3.X
- Comes handy when transfer files(esp during pen testing)
python -m http.server 8000
- Minimal HTTP server that supports GET and HEAD request handlers
- Comes handy when transfer files(esp during pen testing)
python -m SimpleHTTPServer 8000
- The Zen of Python is a collection of software principles that influences the design of Python Programming Language
- Fowiing snippet prints the zen of python
python -m this
- The antigravity module, opens the XKCD comic mentioning Python in a web browser
python -c "import antigravity"
- This snippet will simply print the "Hello, world!" string(Python2.x syntax)
- In Python3, print is a function not a keyword
print "Hello, world!"