Skip to content

Instantly share code, notes, and snippets.


James Bensley jwbensley

View GitHub Profile
jwbensley /
Created October 14, 2022 14:03
Depth first search of a tree with a per-branch "exclude" list
#!/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 /
Created July 29, 2021 16:08
HTTP Server File Upload
# 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 / 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 / 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
PING ( 69(97) bytes of data.
77 bytes from icmp_req=1 ttl=60 time=0.286 ms
77 bytes from icmp_req=2 ttl=60 time=0.320 ms
77 bytes from icmp_req=3 ttl=60 time=0.265 ms
77 bytes from icmp_req=4 ttl=60 time=0.269 ms
77 bytes from icmp_req=5 ttl=60 time=0.286 ms
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
PING ( 1472(1500) bytes of data.
76 bytes from icmp_req=1 ttl=121 (truncated)
76 bytes from icmp_req=2 ttl=121 (truncated)
76 bytes from icmp_req=3 ttl=121 (truncated)
76 bytes from icmp_req=4 ttl=121 (truncated)
76 bytes from icmp_req=5 ttl=121 (truncated)
jwbensley /
Created May 5, 2020 10:20
#!/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])
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 /
Created November 30, 2018 16:19
snmpwalk using SNMPv3
snmpwalk -v 3 -n "" -u $USER -a MD5 -A "$PASS" -x AES -X "$KEY" -l authPriv $HOST .iso
jwbensley /
Created November 30, 2018 16:18
curl -H "Authorization: Token XXXXXXX" -H "Accept: application/json; indent=4" -k
jwbensley /
Created November 30, 2018 15:57 - Use Scapy to generate many ARP entries.
# sudo -H pip3 install scapy
import copy
from scapy.all import *
import time