Skip to content

Instantly share code, notes, and snippets.

View charlestang's full-sized avatar
🤠

Charles Tang charlestang

🤠
View GitHub Profile
@charlestang
charlestang / shadowsocks
Last active July 7, 2020 10:21
This is a init.d script on CentOS 6.x, which is used to help you manage your shadowsocsk-libev server.
#!/bin/bash
#
# shadowsocks-libev This scripts turns shadowsocks server on
#
# Author: Charles Tang <charles.tang@live.com>
#
# description: shadowsocks-libev is a proxy software.
# processname: ss-server
# config: /usr/local/etc/ss-server.conf
# pidfile: /var/run/ss-server.pid
@charlestang
charlestang / bad_ips.txt
Created July 7, 2015 03:42
these IPs frequently try to call my xmlrpc api to do something bad
-A INPUT -s 104.255.67.211/32 -j DROP
-A INPUT -s 172.245.13.250/32 -j DROP
-A INPUT -s 180.97.106.0/24 -j DROP
-A INPUT -s 185.11.146.127/32 -j DROP
-A INPUT -s 185.209.52.0/24 -j DROP
-A INPUT -s 185.62.189.0/24 -j DROP
-A INPUT -s 185.62.190.0/24 -j DROP
-A INPUT -s 188.209.52.0/24 -j DROP
-A INPUT -s 192.227.171.98/32 -j DROP
-A INPUT -s 192.3.194.218/32 -j DROP
@charlestang
charlestang / relative_path.php
Last active November 2, 2015 10:57
计算 $b 相对于 $a 的路径的算法
<?php
function rel($b, $a, $lvl = 1) {
$first_b = retrieve_first($b);
$first_a = retrieve_first($a);
if (!$first_a) {
return ltrim($b, '/');
}
if (!$first_b) {
return '../' . rel($b, rm_first($a), $lvl);
@charlestang
charlestang / cookie.js
Created March 20, 2015 11:44
cookies api
@charlestang
charlestang / shadow_daemon.sh
Created July 22, 2013 15:57
这个脚本是服务器上shadowsocks的服务器的守护进程,脚本放在config.json相同的目录中,然后配置一个每分钟运行的crontab,该脚本会保证自己只有一个实例在运行,脚本的功能是每秒扫瞄一次,看ssserver进程是否还在运行中,如果找不到ssserver,就重新启动一个ssserver。
#!/bin/bash
base_path=$(cd `dirname $0`;pwd)
daemon_pid=$base_path/daemon.pid
if [ -e $daemon_pid ]; then
pid=`cat $daemon_pid`
exist=`ps aux | grep $pid | grep -v grep`
if [ ${#exist} -gt 0 ]; then
exit 0
else
echo -n '' > $daemon_pid
@charlestang
charlestang / build_ssh_tunnel.sh
Created November 20, 2012 13:46
Build a ssh tunnel in the background and test the port every 30 seconds if tunnel gone away build again.
#!/bin/bash
while true ; do
listen=`netstat -f inet -p tcp -nRa | grep 'LISTEN' | awk '{ print $4 }' | grep 18080`
if [ -z $listen ]; then
nohup ssh -ntt -D 18080 user@domain.com > /dev/null 2>&1 &
fi
sleep 30
done
@charlestang
charlestang / goto.sh
Last active October 12, 2015 17:17
Interactively selecting server to connect from config file
#!/bin/bash
server_config=~/.ssh/server_config
echo 'Servers:'
cat -n $server_config
echo 'Please seletct: >'
read n
echo 'Connecting....'
command=`sed -n ${n}p $server_config | awk -F'#' '{ print $1; }'`
$command
@charlestang
charlestang / build_ssh_tunnel.sh
Created January 28, 2012 10:21
This script is for OS X. It check if the ssh forwording process exists, if not, create one. It is created for adding to crontab.
#!/bin/bash
listen=`netstat -f inet -p tcp -nRa | grep 'LISTEN' | awk '{ print $4 }' | grep 10024`
if [ $listen ]; then
if [ $listen = '127.0.0.1.10024' ]; then
exit
fi
fi
nohup ssh -ntt -D 10024 user@yourdomain.com > /dev/null 2>&1 &
exit