How to create a new user and grant permissions in MySQL and also creating a database ?

sudo mysql [sudo] password for jeffrin: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.30-1 (Debian) Copyright (c) 2000, 2022, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. …

How to install MySQL-Connector-Python module in Debian ?

$pip install mysql-connector-python Defaulting to user installation because normal site-packages is not writeable Collecting mysql-connector-python Downloading mysql_connector_python-8.0.30-cp310-cp310-manylinux1_x86_64.whl (25.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 25.4/25.4 MB 2.3 MB/s eta 0:00:00 Collecting protobuf<=3.20.1,>=3.11.0 Downloading protobuf-3.20.1-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.1/1.1 MB 1.4 MB/s eta 0:00:00 Installing collected packages: protobuf, mysql-connector-python Successfully installed mysql-connector-python-8.0.30 protobuf-3.20.1

How to install mysql-connector method for python in Debian ?

$pip3 install mysql-connector Defaulting to user installation because normal site-packages is not writeable Collecting mysql-connector Downloading mysql-connector-2.2.9.tar.gz (11.9 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.9/11.9 MB 2.0 MB/s eta 0:00:00 Preparing metadata (setup.py) … done Building wheels for collected packages: mysql-connector Building wheel for mysql-connector (setup.py) … done Created wheel for mysql-connector: filename=mysql_connector-2.2.9-cp310-cp310-linux_x86_64.whl size=247966 sha256=24d2cc6f0033919bd3bbe1a59ef54a72bc3f302b9c4526115dea2c95e17d4fa7 Stored in directory: /home/jeffrin/.cache/pip/wheels/76/48/9b/da67ff1a18fe8e9d428f9b1a177716d4a7d363d2bbe83bf6cf …

Program to POST a form using HTTP with requests

$cat form_post_method.py #!/usr/bin/env python3 import requests data_dictionary = {‘custname’: ‘customer’,’custtel’: ‘323232’, ‘size’: ‘large’,’custemail’: ’email@domain.com’} response = requests.post(“http://httpbin.org/post”,data=data_dictionary) # we then print out the http status_code print(“HTTP Status Code: ” + str(response.status_code)) if response.status_code == 200: print(response.text) $python3 form_post_method.py HTTP Status Code: 200 { “args”: {}, “data”: “”, “files”: {}, “form”: { “custemail”: “email@domain.com”, “custname”: “customer”, …

Program to do digest authentication using requests module

$cat digest_authentication.py #!/usr/bin/env python3 import requests from requests.auth import HTTPDigestAuth url = ‘http://httpbin.org/digest-auth/auth/user/pass’ response = requests.get(url, auth=HTTPDigestAuth(‘user’, ‘pass’)) print(‘Response.status_code:’+ str(response.status_code)) if response.status_code == 200: print(‘Login successful :’+str(response.json())) $ $python3 digest_authentication.py Response.status_code:200 Login successful :{‘authenticated’: True, ‘user’: ‘user’}

Program to do basic authentication using “requests” module in python

$python3 basic_authentication.py Response.status_code:401 $cat basic_authentication.py #!/usr/bin/env python3 import requests from requests.auth import HTTPBasicAuth requests.get(‘https://api.github.com/user’, auth=HTTPBasicAuth(‘user’, ‘password’)) # requests provides a shorthand for this authentication method response = requests.get(‘https://api.github.com/user’, auth=(‘user’, ‘password’)) print(‘Response.status_code:’+ str(response.status_code)) if response.status_code == 200: print(‘Login successful :’+response.text) $

Counting and printing packets using pyshark

#!/usr/bin/env python3 import pyshark packets_array = [] def counter(*args): packets_array.append(args[0]) def count_packets(): cap = pyshark.FileCapture(‘http.cap’, keep_packets=False) cap.apply_on_packets(counter, timeout=10000) return len(packets_array) print(“Packets number:”+str(count_packets())) for packet in packets_array: print(packet) break $python3 count_packets.py Packets number:43 Packet (Length: 62) Layer ETH: Destination: fe:ff:20:00:01:00 Address: fe:ff:20:00:01:00 …. ..1. …. …. …. …. = LG bit: Locally administered address (this is …

Read on packet capturing using pyshark

$python3 read_pcap.py > pcap-result.txt $cat read_pcap.py #!/usr/bin/env python3 import pyshark #cap = pyshark.FileCapture(‘http.cap’, display_filter=”dns”) #for pkt in cap: # print(pkt) cap = pyshark.FileCapture(‘http.cap’, keep_packets=False) def print_info_layer(packet): print(“[Protocol:] “+packet.highest_layer+” [Source IP:] “+packet.ip.src+” [Destination IP:]”+packet.ip.dst) cap.apply_on_packets(print_info_layer) $cat pcap-result.txt [Protocol:] TCP [Source IP:] 145.254.160.237 [Destination IP:]65.208.228.223 [Protocol:] TCP [Source IP:] 65.208.228.223 [Destination IP:]145.254.160.237 [Protocol:] TCP [Source IP:] 145.254.160.237 …

Using streams and file descriptors with fprintf and dprintf respectively

$ls ascii-table.c avg.txt case-changer.c env-var-set.c functions_ver1.c mph-to-kph.c output.c ascii-table.md avg-with-garbage.txt env-var.c exist.sh functions_ver2.c mph-to-kph_v2.c $gcc output.c -o output $./output A regular message on stdout Also a regular message on stdout An error message on stderr A regular message, printed to fd 1 An error message, printed to fd 2 $cat output.c #define _POSIX_C_SOURCE 200809L #include …