Skip to content

Instantly share code, notes, and snippets.

View excelwang's full-sized avatar
🎯
Focusing

Huajin Wang excelwang

🎯
Focusing
  • Computer Network Information Center, Chinese Academy of Sciences
View GitHub Profile
@excelwang
excelwang / wg-top-user
Last active April 8, 2021 09:51
a tool to monitor wg-active-user
#!/bin/bash
cd '/etc/wireguard'
while [ 1 ]
do
clear
echo `date` ' Top Active Wireguard Peers:'
echo '-------------------------------------------------------------------'
echo 'User,Client IP,VPN IP,Last Handshake'| sed 's/,/,|,/g' | column -s ',' -t
echo '-------------------------------------------------------------------'
./active_user|grep --color=always -E ", ([0-9]+ minute|[0-9]+ second)" | sed 's/,/,|,/g' | column -s ',' -t
@excelwang
excelwang / wg-active_user
Last active April 8, 2021 09:49
a tool to display active wg peers added by wg-add-peer.py
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import os
os.chdir("/etc/wireguard")
users = []
@excelwang
excelwang / wg-add-peer
Last active April 8, 2021 08:39
python wg-add-peer.py wg0 testuser
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os
import sys
import re
group=sys.argv[1]#config file prefix
user=sys.argv[2]#user remark
ip_begin=''
ip_ends=[]
### DML ###
# Keyspace Name
keyspace: stresscql
# The CQL for creating a keyspace (optional if it already exists)
keyspace_definition: |
CREATE KEYSPACE stresscql WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
# Table name
@excelwang
excelwang / ntfs
Last active January 8, 2017 13:31
Re-mount the latest attached NTFS disk on macOS manually: 1) Put it into a Spotlight searchable folder, 2) attribute it executable, and 3) call it using Spotlight when you need to write to the latest attached NTFS disk.
#!/bin/bash
dev=`df|tail -1`
volume=`echo ${dev##*% }|sed 's/\ /\\\ /g'`
dev=${dev%% *}
diskutil info $dev|grep NTFS>/dev/null
if [ $? -ne 0 ] ; then
echo "Latest mounted disk ($volume) is not a NTFS device!"
echo "Press Return button to exit!"
read
else