-
Notifications
You must be signed in to change notification settings - Fork 8
/
build-rpglist.sh
executable file
·134 lines (117 loc) · 3.15 KB
/
build-rpglist.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
api_key="$1"
if [ ${#api_key} -ne 32 ]; then
echo -e "Usage: \n\t $(basename "$0") API_KEY\n"
echo "ERROR: need a valid api_key, get it from https://steamcommunity.com/dev/apikey"
exit 1
fi
rpg_name_pattern=$(echo '
[^非]RPG
| 戮
| 弑
| 巅
| 凡
| 玄
| 天下
| 天域
| 神域
| 完美世界
| 一念仙行
| 窥仙之路
| 风花雪月
| 暗黑之魂
| 午夜狂欢
| 無人永生
| 神之右手
| 军魂
| 星缘
| 破晓
| 腐尸之地
| 猎人
| 通天塔
| 无法逃脱
| 穷途末路
| 众神传说
| 上帝
| HTの
' \
| tr -d '[:space:]'
)
mkdir -p output && cd output
# Get full list
curl -sS --get \
'http://api.steampowered.com/IGameServersService/GetServerList/v1' \
--header 'Accept: application/json' \
--data-urlencode "key=$api_key" \
--data-urlencode "filter=\appid\550\nor\9\gametype\official\white\1\region\0\region\1\region\2\region\3\region\5\region\6\region\7" \
--data-urlencode "limit=100000" \
> serverlist_full.json
# Generate rpglist.json
cat serverlist_full.json \
| jq '
{
"ver": "5.1",
"tag": "ipblacklist",
"data": [
.response.servers[]
| with_entries( select([.key] | inside( ["name", "addr"] )) )
| select( .name | test("'"$rpg_name_pattern"'") )
| .addr = (.addr | split(":") | .[0])
| .["raddr"] = .addr | del(.addr)
| .["memo"] = .name | del(.name)
]
| unique_by(.raddr)
}' \
> rpglist.json
# Generate for win: BlockRpg.ps1
iplist_ps1=$(cat rpglist.json | jq --raw-output '
.data
| map(.raddr)
| join("\", \"")
')
echo '
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
exit
}
$rulename = "Block L4D2 RPG Servers"
$iplist = @("'"$iplist_ps1"'")
if ( Get-NetFirewallRule -DisplayName $rulename 2>$null ) {
echo "Updating existing rule: ""$rulename"""
Set-NetFirewallRule `
-DisplayName $rulename `
-RemoteAddress $iplist
} else {
echo "Creating new rule: ""$rulename"""
New-NetFirewallRule `
-DisplayName $rulename `
-Direction Outbound `
-Protocol "udp" `
-Action Block `
-RemoteAddress $iplist
}
Read-Host -Prompt "------------- Done. -------------" | Out-Null
' \
> BlockRpg.ps1
# Generate for unix: block-rpg.sh
iplistname=l4d2-rpg-blacklist
iplist_bash=$(cat rpglist.json | jq --raw-output '
.data
| map(["add '"$iplistname"'", .raddr])[]
| join(" ")
')
echo '#!/bin/bash
iplistname='"$iplistname"'
tmpfile=$(mktemp -t ipset-XXXX)
cat << EOF > $tmpfile
create $iplistname hash:ip family inet hashsize 4096 maxelem 65536
flush $iplistname
'"$iplist_bash"'
EOF
ipset restore -! < $tmpfile
rm -rf $tmpfile
if [ $(iptables -L | grep -c $iplistname) -eq 0 ]; then
iptables -I OUTPUT -p UDP -m set --match-set $iplistname dst -j DROP
fi
' \
> block-rpg.sh