Skip to content

Instantly share code, notes, and snippets.

@pankpan
pankpan / CentOS-Base.repo
Last active June 1, 2021 14:09
CentOS-Base.repo for CentOS 6
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
@pankpan
pankpan / iptables.sh
Created May 3, 2021 04:04
iptables security policy for Cloudflare
#!/bin/bash
iptables -F
iptables -P INPUT DROP
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
for IP in `curl -s https://www.cloudflare.com/ips-v4`
do
iptables -A INPUT -s $IP -p tcp -m multiport --dport 80,443 -j ACCEPT
done
@pankpan
pankpan / skype-send-message.sh
Last active June 1, 2021 14:11
Skype Bot API send message BASH script
#!/bin/bash
# To get TOKEN, ref this gist https://gist.github.com/pankpan/ad68f50cd44c1dae9203d29964d579e5
# TO is personal uid or conversation id
TOKEN=
TO=
curl -sd '{"type":"message","text":"Test 20210601"}' -H "Authorization: Bearer $TOKEN" https://smba.trafficmanager.net/apis/v3/conversations/$TO/activities
@pankpan
pankpan / skype-get-token.sh
Last active June 1, 2021 14:11
Skype Bot API get token BASH script
#!/bin/bash
# Get skype bot token to send message, fill your CLIENT_ID and CLIENT_SECRET
CLIENT_ID=
CLIENT_SECRET=
TOKEN=`curl -sd "client_id=$CLIENT_ID&client_secret=$CLIENT_SECRET&grant_type=client_credentials&scope=https://api.botframework.com/.default" https://login.microsoftonline.com/common/oauth2/v2.0/token | jq -r .request_token`
echo $TOKEN
@pankpan
pankpan / alexa-top-50-sites-dns-bench.sh
Created June 25, 2021 16:13
Measure DNS speed by query Alexa top 50 sites NS and A record
#!/bin/bash
TEMP=/tmp/alexa.html
if [ -z $1 ] ; then
echo "`basename $0` {dns}"
else
DNS=$1
[ -f $TEMP ] || curl -s https://www.alexa.com/topsites > $TEMP
T1=`date +%s.%N`
for HOST in `awk -F[\"\/] '/href=..siteinfo\// {print $4}' $TEMP`
@pankpan
pankpan / linux-auto-login.sh
Created July 3, 2021 07:32
enable Linux console auto login script
#!/bin/sh
sed -i 's/ExecStart.*/ExecStart=-\/sbin\/agetty -a root %I \$TERM/' /usr/lib/systemd/system/getty@.service
@pankpan
pankpan / kick-out-user-by-ip.sh
Last active July 5, 2021 01:23
Force kick out user by IP address for Linux
#!/bin/sh
if [ -z $1 ] ; then
echo "`basename $0` {ip}"
else
TEMP=/tmp/psauxw.tmp
ps auxw > $TEMP
for T in `w | grep -w $1 | awk '{print $2}'`
do
echo Logout $T
grep -w $T $TEMP | awk '{print $2}' | xargs kill -9
@pankpan
pankpan / get-tw-ips.sh
Created July 10, 2021 15:33
Get Taiwan IPv4 Addresses from APNIC
#!/bin/sh
# netmask from http://trap.mtview.ca.us/~talby/netmask_2.4.tar.gz
netmask `curl -s http://ftp.apnic.net/stats/apnic/delegated-apnic-latest | awk -F'|' '/TW\|ipv4/ {print $4":+"($5-1)}'`
@pankpan
pankpan / LINE_SCALE.bat
Created July 27, 2021 14:59
LINE loader with QT_SCALE_FACTOR variable
set QT_SCALE_FACTOR=1.25
start %LOCALAPPDATA%\LINE\bin\LineLauncher.exe
@pankpan
pankpan / volley_post_data_with_header.kt
Last active August 29, 2021 06:34
Android Kotlin Volley POST data with header
// implementation 'com.android.volley:volley:1.2.1'
import com.android.volley.Response
import com.android.volley.toolbox.StringRequest
import com.android.volley.toolbox.Volley
var apiUrl="https://your-api-url.com/"
val request: StringRequest = object : StringRequest(
Method.POST, apiUrl,
Response.Listener { response ->
if (response != null) {