Post

Python – Scripting Stuff !!!

Python – Scripting Stuff !!!

#Python for Hackers

ArgParse (Provide Interactive Help Menu)

1
2
3
4
5
6
7
import argparse
parser = argparse.ArgumentParser(
    prog='ScriptName',description='Short description of the script.',epilog='Thank you for using this tool!'
    )

parser.add_argument('--ip', help="Attacker IP address", required=True)
args = parser.parse_args()

After defining all this above arguments.know you can run the --help or -h for help menu.

1
2
3
python3 file_name.py --help

python3 file_name.py -h

Request (Provide Us to send and Retrive date)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import requests
url   = ""
token = ""
headers = {
    "Authorization": f"Bearer {token}",
    "Content-Type": "application/json"
}

payload = {
    "password": "new_password_here",
    "id": 1
}

# Multiple Request Methods
r = requests.get(url, headers=headers, json=payload)
r = requests.post(url, headers=headers, json=payload)
r = requests.put(url, headers=headers, json=payload)
print(f"Status code: {r.status_code}")
print(f"Response: {r.text}")

Re (Pattern text Extraction from websites)

1
2
3
4
5
6
import re
r = requests.get(url, headers=headers, json=payload)
print(f"Status code: {r.status_code}")
print(f"Response: {r.text}")
match = re.search(r'bug\{[a-zA-Z0-9_]+\}', r.text)
print(match.group())

Resources

To explore the full capabilities of the argparse module, refer to the official documentation :- link

This post is licensed under CC BY 4.0 by the author.