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 …

Check if a string has only numerals and do conversion if it is true

$ls ascii-table avg-with-garbage.txt env-var.c functions_ver1 mph-to-kph ascii-table.c case-changer env-var-set functions_ver1.c mph-to-kph.c ascii-table.md case-changer.c env-var-set.c functions_ver2 mph-to-kph_v2.c avg.txt env-var exist.sh functions_ver2.c output.c $./mph-to-kph 564 907.7 $cat mph-to-kph.c #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char mph[10] = { 0 }; while(fgets(mph, sizeof(mph), stdin) != NULL) { /* Check if mph is numeric * (and …

Exiting a program using exit() function

$ls ascii-table avg.txt case-changer.c env-var-set functions_ver1 mph-to-kph.c ascii-table.c avg-with-garbage.txt env-var env-var-set.c functions_ver1.c mph-to-kph_v2.c ascii-table.md case-changer env-var.c exist.sh functions_ver2.c output.c $zile functions_ver2.c $gcc functions_ver2.c -o functions_ver2 $./functions_ver2 Inside main Calling function one Inside function one Calling function two Inside function two Returning with (error) from function two $cat functions_ver2.c #include <stdio.h> #include <stdlib.h> int func1(void); int …