Skip to content

Instantly share code, notes, and snippets.

@sjtosco
sjtosco / get_gw_by_iface.sh
Last active March 20, 2024 13:40
Check router (gateway) of specific interface
get_gw_by_iface(){
# Return router ip of interface
# Usage: get_gw_by_iface IFACE
sudo traceroute -n -i $1 -m1 $(get-extip) 2>/dev/null | tail -1 | awk '{print $2}'
}
get_gw_by_iface2(){
# Return router ip of interface (multitable)
# Usage: get_gw_by_iface IFACE
ip route list table all | awk '/default via/' | grep enp1s0 | awk '{print $3}'
@sjtosco
sjtosco / ss-parse.sh
Created February 14, 2024 15:26 — forked from ffund/ss-parse.sh
Parses SS output for BBR flow live, and outputs in CSV format. Adjust the sleep interval if you want. Use as: `./live-ss-parse.sh 10.0.0.1 5201 | tee outfile.csv` where the argument is the peer IP address and port of the flow you are interested in.
#!/bin/bash
dst=$1
dstport=$2
while [ 1 ]; do
ts=$(date +%s.%N)
line=$(ss -eipn dst "$dst:$dstport" | grep "bbr")
rto=$(echo $line | grep -oP '\brto:.*?(\s|$)' | awk -F '[:,]' '{print $2}' | tr -d ' ')
rttvals=$(echo $line | grep -oP '\brtt:.*?(\s|$)' | awk -F '[:/]' '{print $2","$3}' | tr -d ' ')
@sjtosco
sjtosco / load_two_hello_docker.sh
Created June 28, 2023 15:01
Docker hello container demos
# NGINX Hello app
docker run --rm --name nginx-hello -p 8081:80 -d nginxdemos/hello
# GOOGLE Hello app ver 1.0
docker run --rm --name hello-app -p 8080:8080 -d gcr.io/google-samples/hello-app:1.0
# Test in browser with http://localhost:8080 or http://localhost:8081
@sjtosco
sjtosco / python.json
Created June 13, 2023 04:21 — forked from prandelicious/python.json
[VS Code snippet] Create default python header content
"Default Header": {
"prefix": "header",
"body": [
"#!/usr/bin/env python",
"# -*- coding: utf-8 -*-",
"\"\"\"${1:Custom module name or brief description}.\n",
"${2:Enter description of this module}",
"",
"__author__ = ${3:[authors]}",
"__copyright__ = Copyright 2018",
@sjtosco
sjtosco / config.sh
Created February 24, 2023 21:58 — forked from vietdien2005/config.sh
Fix force gdm login screen to the primary monitor
sudo cp ~/.config/monitors.xml /var/lib/gdm3/.config/
@sjtosco
sjtosco / Docker mariadb+phpmyadmin
Created August 8, 2019 23:09 — forked from alexishida/Docker mariadb+phpmyadmin
Docker mariadb+phpmyadmin
docker run -d \
--name=mariadb \
--restart=always \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=root \
-v /storage/mariadb:/var/lib/mysql \
-p 3306:3306 \
mariadb:latest
docker run -d \
@sjtosco
sjtosco / getLocalIP.js
Created July 4, 2019 13:07 — forked from hectorguo/getLocalIP.js
Get local IP address through Javascript
/**
* Get Local IP Address
*
* @returns Promise Object
*
* getLocalIP().then((ipAddr) => {
* console.log(ipAddr); // 192.168.0.122
* });
*/
function getLocalIP() {
@sjtosco
sjtosco / remove-all-from-docker.sh
Created June 11, 2019 19:31 — forked from beeman/remove-all-from-docker.sh
Remove all from Docker
# Stop all containers
docker stop `docker ps -qa`
# Remove all containers
docker rm `docker ps -qa`
# Remove all images
docker rmi -f `docker images -qa `
# Remove all volumes
@sjtosco
sjtosco / measure.py
Last active April 3, 2019 13:48 — forked from racerxdl/measure.py
Linux Network Traffic Measure/Calculator Python Script
#!/usr/bin/env python
'''
_______ ______
|_ _\ \ / / ___|
| | \ \ / /\___ \
| | \ V / ___) |
|_| \_/ |____/
Teske Virtual System