Skip to content

Instantly share code, notes, and snippets.

Avatar

James Bensley jwbensley

View GitHub Profile
@jwbensley
jwbensley / ex-members.py
Created October 14, 2022 14:03
Depth first search of a tree with a per-branch "exclude" list
View ex-members.py
#!/usr/bin/env python3
"""
ASN to AS-SET mapping:
AS4200000011 -> AS-A1
AS4200000021 -> AS-B1
AS4200000022 -> AS-B2
AS4200000023 -> AS-B3
AS4200000031 -> AS-C1
AS4200000032 -> AS-C2
@jwbensley
jwbensley / http_upload.py
Created July 29, 2021 16:08
HTTP Server File Upload
View http_upload.py
#/usr/bin/python
#
# HTTP server with a HTML form that allows to upload files to the server.
# Files are stored in a folder named "files" inside the current directory.
from os import curdir
from os.path import join as pjoin
from http.server import BaseHTTPRequestHandler, HTTPServer
@jwbensley
jwbensley / memcpy_aligned.c
Created June 26, 2020 08:58
memcpy() using cache and page aligned values
View memcpy_aligned.c
#include <inttypes.h> // uint*_t
#include <stdio.h> // perror(), printf()
#include <stdlib.h> // memcpy, posix_memalign()
#include <string.h> // malloc()
#include <time.h> // clock_t, CLOCKS_PER_SEC
#include <unistd.h> // getpagesize()
static inline void memcpy_aligned(void *to, const void *from, size_t len) {
if (len <= 64) {
memcpy(to, from, 64);
@jwbensley
jwbensley / BBC Pings
Created June 26, 2020 08:56
BBC Pings
View BBC Pings
# Linux 3.2 (DON'T ASK!) v4
$ping -M do -c 5 -s 69 151.101.192.81
PING 151.101.192.81 (151.101.192.81) 69(97) bytes of data.
77 bytes from 151.101.192.81: icmp_req=1 ttl=60 time=0.286 ms
77 bytes from 151.101.192.81: icmp_req=2 ttl=60 time=0.320 ms
77 bytes from 151.101.192.81: icmp_req=3 ttl=60 time=0.265 ms
77 bytes from 151.101.192.81: icmp_req=4 ttl=60 time=0.269 ms
77 bytes from 151.101.192.81: icmp_req=5 ttl=60 time=0.286 ms
@jwbensley
jwbensley / Google Pings
Last active June 26, 2020 08:56
Google Pings
View Google Pings
# Linux 3.2 (DON'T ASK!) v4
$ping -M do -c 5 -s 1472 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 1472(1500) bytes of data.
76 bytes from 8.8.8.8: icmp_req=1 ttl=121 (truncated)
76 bytes from 8.8.8.8: icmp_req=2 ttl=121 (truncated)
76 bytes from 8.8.8.8: icmp_req=3 ttl=121 (truncated)
76 bytes from 8.8.8.8: icmp_req=4 ttl=121 (truncated)
76 bytes from 8.8.8.8: icmp_req=5 ttl=121 (truncated)
@jwbensley
jwbensley / jinja2_render.py
Created May 5, 2020 10:20
jinja2_render.py
View jinja2_render.py
#!/usr/bin/env python3
# pip3 install jinja2
from jinja2 import Environment, FileSystemLoader
import sys
file_loader = FileSystemLoader('.')
env = Environment(loader=file_loader)
template = env.get_template(sys.argv[1])
print(template.render())
View af_packet_systap
// Not all functions are referenced below are called, that is intentional to verify that they are not being called.
// Provide timestamps:
function print_ts() {
ts = gettimeofday_us();
printf("[%10d.%06d] ", ts/1000000, ts%1000000);
}
@jwbensley
jwbensley / snmpv3walk.sh
Created November 30, 2018 16:19
snmpwalk using SNMPv3
View snmpv3walk.sh
snmpwalk -v 3 -n "" -u $USER -a MD5 -A "$PASS" -x AES -X "$KEY" -l authPriv $HOST .iso
@jwbensley
jwbensley / curl.sh
Created November 30, 2018 16:18
CURL REST API
View curl.sh
curl -H "Authorization: Token XXXXXXX" -H "Accept: application/json; indent=4" -k https://myapp.net/api/get/object/1
@jwbensley
jwbensley / generate_macs.py
Created November 30, 2018 15:57
generate_macs.py - Use Scapy to generate many ARP entries.
View generate_macs.py
#!/usr/bin/python3
# sudo -H pip3 install scapy
import copy
from scapy.all import *
import time