Skip to content

Instantly share code, notes, and snippets.

View iximiuz's full-sized avatar
🪲

Ivan Velichko iximiuz

🪲
View GitHub Profile
{"time": "2023-12-11T00:00:01.123Z", "method": "GET", "path": "/foo/bar", "status_code": 200, "content_length": 423}
{"time": "2023-12-11T00:01:01.123Z", "method": "POST", "path": "/foo/bar", "status_code": 200, "content_length": 553}
{"time": "2023-12-11T00:02:01.123Z", "method": "GET", "path": "/foo/baz", "status_code": 200, "content_length": 345}
{"time": "2023-12-11T00:03:01.123Z", "method": "GET", "path": "/foo/baz", "status_code": 401, "content_length": 235}
# syntax=docker/dockerfile:1
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=UTC
RUN <<EOF
set -eu
apt-get update
@iximiuz
iximiuz / net_lab_l3_to_l2_mapping.sh
Created March 18, 2021 08:46
Sets up IP subnets over a single Ethernet broadcast domain formed by a Linux bridge.
#!/usr/bin/env bash
set -euo pipefail
create_bridge() {
local nsname="$1"
local ifname="$2"
echo "Creating bridge ${nsname}/${ifname}"
@iximiuz
iximiuz / net_lab_simple_vlan.sh
Last active November 20, 2022 23:33
Configure VLAN tagging on a Linux bridge.
#!/usr/bin/env bash
set -euo pipefail
create_bridge() {
local nsname="$1"
local ifname="$2"
echo "Creating bridge ${nsname}/${ifname}"
@iximiuz
iximiuz / ethsend.py
Last active November 14, 2024 12:44
Send Ethernet frames from Python.
#!/usr/bin/env python3
# Usage: ethsend.py eth0 ff:ff:ff:ff:ff:ff 'Hello everybody!'
# ethsend.py eth0 06:e5:f0:20:af:7a 'Hello 06:e5:f0:20:af:7a!'
#
# Note: CAP_NET_RAW capability is required to use SOCK_RAW
import fcntl
import socket
import struct
@iximiuz
iximiuz / net_lab_broadcast_domains.sh
Last active January 13, 2024 22:17
A bunch of helper functions to create Linux bridges, network namespaces, and interconnect everything using veth pairs.
#!/usr/bin/env bash
set -xeuo pipefail
create_bridge() {
local nsname="$1"
local ifname="$2"
echo "Creating bridge ${nsname}/${ifname}"
#!/usr/bin/env python3
import json
import sys
for line in sys.stdin:
ds = eval(line)
print(json.dumps(ds))
@iximiuz
iximiuz / serv_async.py
Last active February 13, 2024 11:00
Python Web Servers
# python3
import asyncio
import sys
counter = 0
async def run_server(host, port):
server = await asyncio.start_server(serve_client, host, port)
await server.serve_forever()
@iximiuz
iximiuz / walkdir.js
Created March 13, 2019 13:43
Tiny recursive walkdir (aka readdir) in JavaScript
const fs = require('fs');
const path = require('path');
async function *walkdir(dir) {
const stack = [dir];
while (stack.length) {
const filename = stack.pop();
const stat = await fs.promises.stat(filename);
if (stat.isDirectory()) {
const files = (await fs.promises.readdir(filename))
@iximiuz
iximiuz / keep-me-alive.js
Last active February 3, 2022 01:11
Node.js http server keep-alive behaviour test
const http = require('http');
const log = console.log;
console.log = (...args) => {
log.apply(console, [new Date().toISOString()].concat(args));
};
const port = process.argv[2];
const server = http.createServer((req, res) => {
console.log('Incoming request');