Skip to content

Commit

Permalink
生成一键式脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
yxnan committed Dec 3, 2023
1 parent ac63cb0 commit 7d7de1f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 6 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ jobs:
env:
API_KEY: ${{ secrets.api_key }}
run: ./build-rpglist.sh "$API_KEY"

- name: Set date env
run: echo "TODAY=$(date '+%Y/%m/%d')" >> $GITHUB_ENV

- name: Update Release
uses: softprops/action-gh-release@v1
with:
files: rpglist.json
tag_name: latest
name: ${{ env.TODAY }}
files: |
rpglist.json
BlockRpg.ps1
block-rpg.sh
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@

获取地址1:https://docs.qq.com/doc/DQnlEZWNjUE13aWlI

获取地址2:[Release](https://github.com/yxnan/block-l4d2-rpg-servers/releases/latest/download/rpglist.json)
获取地址2:[Release](https://github.com/yxnan/block-l4d2-rpg-servers/releases/tag/latest)

# 屏蔽方法

### Windows

获取上述的`rpglist.json`,导入火绒或者其他类似能提供IP过滤名单的软件即可
下列两种方法任选其一:

1. Release获取`BlockRpg.ps1`,使用管理员权限执行即可
2. Release获取`rpglist.json`,导入火绒或者其他类似能提供IP过滤名单的软件即可

### Linux

运行:
1. Release获取`block-rpg.sh`,使用 root 权限执行
2. Release获取`rpglist.json`,执行下面命令导入:

```bash
sudo ./iptables-import.sh rpglist.json # 换成你下载的实际路径
Expand Down
59 changes: 59 additions & 0 deletions build-rpglist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ rpg_name_pattern=$(echo '
| tr -d '[:space:]'
)

# Generate rpglist.json
curl -sS --get \
'http://api.steampowered.com/IGameServersService/GetServerList/v1' \
--header 'Accept: application/json' \
Expand All @@ -58,3 +59,61 @@ curl -sS --get \
| unique_by(.raddr)
}' \
> rpglist.json

# Generate for win: BlockRpg.ps1
iplist_ps1=$(cat rpglist.json | jq --raw-output '
.data
| map(.raddr)
| join("\", \"")
')

echo '
$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
}
echo "Done."
' \
> 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

0 comments on commit 7d7de1f

Please sign in to comment.