Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
5092f76
Update autoinstall.sh
somnifex May 27, 2022
d69beff
Update UPCNet.sh
somnifex May 27, 2022
ac7f9cf
Update autoinstall.sh
somnifex May 27, 2022
7741ff2
Update README.md
somnifex May 27, 2022
4acbcb6
Update autoinstall.sh
somnifex May 27, 2022
aa7f457
Update UPCNet.sh
somnifex May 27, 2022
f842918
Update autoinstall.sh
somnifex May 27, 2022
f538179
Update UPCNet.sh
somnifex May 27, 2022
086d943
Update README.md
somnifex Nov 3, 2022
6046358
Create autoinstallNoUpdate.sh
somnifex Nov 4, 2022
f7246d8
Update README.md
somnifex Nov 4, 2022
2705b73
change ping
somnifex Mar 17, 2023
c258446
你觉得需要重启网卡吗
somnifex Apr 19, 2023
119b871
Update README.md
somnifex Jun 6, 2023
922ad0f
Update UPCNet.sh
somnifex Jun 6, 2023
48bdc5b
update ping url list
somnifex Jun 6, 2023
51a7e67
update ping url list
somnifex Jun 6, 2023
ed39244
update ping url list
somnifex Jun 6, 2023
14b08e5
update ping url list
somnifex Jun 6, 2023
64b8bbb
update ping url list
somnifex Jun 6, 2023
4f78157
Update README.md
somnifex Jul 22, 2023
e8db2e2
Update README.md
somnifex Jul 22, 2023
4d29445
Update UPCNet.sh
somnifex Aug 14, 2023
f3599d2
Update UPCNet.sh
somnifex Aug 14, 2023
87f2185
Update UPCNet.sh
somnifex Aug 16, 2023
638fc8c
Update UPCNet.sh
somnifex Aug 16, 2023
4de4a1b
Update UPCNet.sh
somnifex Aug 18, 2023
9a2c928
Update UPCNet.sh
somnifex Sep 17, 2023
93686ff
Update UPCNet.sh
somnifex Sep 17, 2023
7892753
Update UPCNet.sh
somnifex Dec 12, 2023
eb476c2
Update UPCNet.sh
somnifex Dec 12, 2023
5b7b808
Update autoinstall.sh
somnifex Dec 12, 2023
f63d861
Update autoinstallNoUpdate.sh
somnifex Dec 12, 2023
d5f9f62
Update autoinstall.sh
somnifex Dec 12, 2023
ea71627
Update UPCNet.sh
somnifex Dec 12, 2023
2da432d
Update UPCNet.sh
somnifex Dec 12, 2023
2cf746b
Update UPCNet.sh
somnifex Dec 12, 2023
3835342
Update UPCNet.sh
somnifex Dec 12, 2023
f112f9d
Update UPCNet.sh
somnifex Dec 12, 2023
03c84d5
Update UPCNet.sh
somnifex Dec 12, 2023
8d2fe76
Update UPCNet.sh
somnifex Dec 12, 2023
981c4a7
Update UPCNet.sh
somnifex Dec 15, 2023
1a24496
Update autoinstall.sh
somnifex Dec 15, 2023
08c7cb6
Update autoinstallNoUpdate.sh
somnifex Dec 15, 2023
47c84d7
Update README.md
somnifex Dec 17, 2023
2a82979
Update UPCNet.sh
somnifex Mar 14, 2024
fc4d8b2
Update README.md
somnifex May 5, 2024
f37dbfb
Update autoinstall.sh
somnifex May 5, 2024
81bb34f
Update autoinstallNoUpdate.sh
somnifex May 5, 2024
d9e4ed2
Update UPCNet.sh
somnifex May 5, 2024
1b4dd61
Update autoinstall.sh
somnifex Jul 4, 2025
97fa2ff
Update autoinstallNoUpdate.sh
somnifex Jul 4, 2025
0d42f34
Update README.md
somnifex Jul 4, 2025
6708c86
Update UPCNet.sh
somnifex Jul 7, 2025
f960401
Update UPCNet.sh
somnifex Jul 7, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,69 @@

![飞天面条教保佑你的代码](https://cdn.rawgit.com/LunaGao/BlessYourCodeTag/master/tags/ramen.svg)

## 由于portal升级,queryString等参数发生变化,脚本暂时失效

### Openwrt路由器自动安装
在命令行中使用root权限运行以下代码即可
不自动安装curl
````shell
wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/autoinstallNoUpdate.sh && chmod +x autoinstallNoUpdate.sh && sh autoinstallNoUpdate.sh
````
wget --no-check-certificate https://raw.githubusercontent.com/EndangeredF1sh/UPCNet/bash/autoinstall.sh && chmod +x autoinstall.sh && sh autoinstall.sh
自动安装curl
````shell
wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/autoinstall.sh && chmod +x autoinstall.sh && sh autoinstall.sh
````
### Openwrt路由器配置IPV6中继Relay
> 引用自[Yumao's Blog](https://www.yumao.name/read/openwrt-ipv6-bridge-or-nat6/)

LUCI界面中LAN接口设置:
```
路由通告服务:中继
DHCPv6服务:中继
NDP代理:中继
```
检查/etc/config/dhcp文件中,lan的相关参数
```
config dhcp 'lan'
option ra "relay"
option dhcp "relay"
option ndp "relay"
```
修改 /etc/config/dhcp文件中,wan的相关参数
```
config dhcp 'wan'
option interface 'wan'
option dhcpv6 'relay'
option ra 'relay'
option ndp 'relay'
option master '1'

```
添加计划任务
```shell
* * * * * /root/ipv6-bridge.sh
```
/root/ipv6-bridge.sh如下:
```shell
#!/bin/sh
if [ -n "`ip -6 route show default|grep from -m 1`" ];then
logger -t "IPV6" change default gateway without from source
DEFAULT=`ip -6 route show default|grep from -m 1`
#刪除默認路由
ip -6 route del ${DEFAULT}
#添加無from source路由
ip -6 route add `echo ${DEFAULT}|sed -e 's/from [^ ]* //'`
#添加子網内設備通過br-lan訪問
ip -6 route add `echo ${DEFAULT}|grep from|awk '{printf $3}'` dev br-lan metric 128
fi
#刪除之前自動添加的錯誤路由
ip -6 route list|grep -v default|grep -v br-lan|grep static|while read -r s; do ip -6 route del $s; done
#可選:可以根據需求自定義SUBNETEX的值,UPC校园网为240c
SUBNETEX="240c:"
ip -6 route list|grep -v default|grep -v br-lan|grep ${SUBNETEX}|while read -r s; do ip -6 route del $s; done

```
```shell
chmod +x /root/ipv6-bridge.sh
```
### 手动安装方法(其他Linux发行版,暂不支持pandavan)
在UPCNet.sh文件下输入学号(username)、密码(password)和运营商编号(service),然后运行
```
Expand Down
94 changes: 83 additions & 11 deletions UPCNet.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,40 @@
cat=""
back=""
username=""
password=""
service=""
usernameB=""
passwordB=""
serviceB=""

DATE=`date +%Y-%m-%d-%H:%M:%S`
tries=0
echo --- my_watchdog start ---
while [[ $tries -lt 3 ]]
echo "Start detecting network connection status......"
ip_list="47.104.38.82,218.30.118.6,61.241.129.110"
ips=$(echo "$ip_list" | tr ',' ' ')
for ip in $ips
do
if /bin/ping -c 1 114.114.114.114 >/dev/null
if /bin/ping -c 1 "$ip" >/dev/null
then
echo --- exit ---
echo "The network connection is normal, enjoy~"
echo "---close script---"
exit 0
fi
tries=$((tries+1))
sleep 1
done
sleep 1
echo "!!!ERROR: Network connection exception!!!"
echo "Start writing to the log and execute the login script..."
echo $DATE network offline and try to restart... ... >>my_watchdog.log
# /etc/init.d/network restart
# 重启网卡需要吗?
# sleep 3

echo $DATE network restart >>my_watchdog.log
/etc/init.d/network restart
sleep 10
if [ $cat == 2 ]
then
uci set openclash.config.enable='0'
uci commit openclash
/etc/init.d/openclash stop
sleep 10
fi
parameter='userId='${username}'&password='${password}'&service='${service}'&queryString='
location='http://121.251.251.207/eportal/InterFace.do?method=login'
url=`curl -Ls -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36" -o /dev/null -w %{url_effective} http://121.251.251.217`
Expand All @@ -27,5 +44,60 @@ url=${url//&/%2526}
url=${url//:/%253A}
url=${url//\//%252F}
parameter=${parameter}${url}'&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false'
echo $parameter
# echo $parameter
echo -e "Try to log in using the primary account\n"
curl -X POST -d $parameter $location
sleep 8
if [ $back == 2 ]
then
for ip in $ips
do
if /bin/ping -c 1 "$ip" >/dev/null
then
echo -e "\n"
echo "Log in with your primary account, the network is back to normal, enjoy~"
echo "---close script---"
if [ $cat == 2 ]
then
uci set openclash.config.enable='1'
uci commit openclash
reboot
fi
sleep 15
exit 0
fi
done
for ip in $ips
do
if /bin/ping -c 1 "$ip" >/dev/null
then
echo "The network connection is normal, enjoy~"
echo "---close script---"
exit 0
fi
done
echo -e "FAILED, Start trying to log in with an alternate account\n"
parameterB='userId='${usernameB}'&password='${passwordB}'&service='${serviceB}'&queryString='
parameterB=${parameterB}${url}'&operatorPwd=&operatorUserId=&validcode=&passwordEncrypt=false'
# echo $parameterB
curl -X POST -d $parameterB $location
for ip in $ips
do
if /bin/ping -c 1 "$ip" >/dev/null
then
echo -e "\n"
echo "Log in with your alternate account, the network is back to normal, enjoy~"
echo "---close script---"
if [ $cat == 2 ]
then
uci set openclash.config.enable='1'
uci commit openclash
reboot
fi
sleep 15
exit 0

fi
done
echo "You can't sign in with your existing account. Please check your configuration and other network settings and close script"
fi
65 changes: 61 additions & 4 deletions autoinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ fi
echo "Auto install start ..."
opkg update
opkg install curl
wget --no-check-certificate https://raw.githubusercontent.com/EndangeredF1sh/UPCNet/bash/UPCNet.sh && chmod +x UPCNet.sh
wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/UPCNet.sh && chmod +x UPCNet.sh
echo -n "If you have openclash? (1 for no, 2 for yes, default:1) -> "
read cat
cat=${cat:-1}
echo -n "If Backup? (1 for no,2 for yes, default:1) -> "
read bk
bk=${bk:-1}
echo -n "input stuID -> "
read stuID
echo -n "input password -> "
Expand Down Expand Up @@ -56,14 +62,65 @@ read -p "Enter selection [1-5] -> " num
if [[ $num == 5 ]]; then
service="local"
fi
if [ $bk == 2 ]
then
echo -n "input stuID -> "
read stuIDB
echo -n "input password -> "
read passwdB
echo "Select your back service:
1. Campus Network Service
2. China Unicom Network Service
3. China Mobile Network Service
4. China Telecom Network Service
5. Campus Intranet
"
read -p "Enter selection [1-5] -> " num
if [ $num -lt 1 ] || [ $num -gt 5 ];then
echo "invalid selection, exit.";
exit;
fi

if [[ $num == 1 ]]; then
serviceB="default"
fi

if [[ $num == 2 ]]; then
serviceB="unicom"
fi

if [[ $num == 3 ]]; then
serviceB="cmcc"
fi

if [[ $num == 4 ]]; then
serviceB="ctcc"
fi

if [[ $num == 5 ]]; then
serviceB="local"
fi
fi

sed -i '1,3d' UPCNet.sh
if [ $bk == 2 ]
then
sed -i '1,8d' UPCNet.sh
sed -i "1i cat=\"$cat\"" UPCNet.sh
sed -i "1i back=\"$bk\"" UPCNet.sh
sed -i "1i service=\"$service\"" UPCNet.sh
sed -i "1i password=\"$passwd\"" UPCNet.sh
sed -i "1i username=\"$stuID\"" UPCNet.sh


sed -i "1i serviceB=\"$serviceB\"" UPCNet.sh
sed -i "1i passwordB=\"$passwdB\"" UPCNet.sh
sed -i "1i usernameB=\"$stuIDB\"" UPCNet.sh
else
sed -i '1,5d' UPCNet.sh
sed -i "1i cat=\"$cat\"" UPCNet.sh
sed -i "1i back=\"$bk\"" UPCNet.sh
sed -i "1i service=\"$service\"" UPCNet.sh
sed -i "1i password=\"$passwd\"" UPCNet.sh
sed -i "1i username=\"$stuID\"" UPCNet.sh
fi
croncmd="sh ${SHELL_FOLDER}"/UPCNet.sh""
cronjob="*/1 * * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -
Expand Down
129 changes: 129 additions & 0 deletions autoinstallNoUpdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
os_release_path="/etc/os-release"
openwrt_release_path="/etc/openwrt_release"
SHELL_FOLDER=$(dirname $(readlink -f "$0"))
if [ -f "$os_release_path" ];then
source /etc/os-release
else
if [ -f "$openwrt_release_path" ];then
ID="openwrt"
fi
fi

if [[ $ID != "openwrt" ]];then
read -r -p "Mismatch Operation System Detected, Are you sure to install? [Y/n] " response
if [[ $response != "y" && $response != "Y" ]];then
exit 0
fi
fi

echo "Auto install start ..."
wget --no-check-certificate https://raw.githubusercontent.com/somnifex/UPCNet/bash/UPCNet.sh && chmod +x UPCNet.sh
echo -n "If you have openclash? (1 for no, 2 for yes, default:1) -> "
read cat
cat=${cat:-1}
echo -n "If Backup? (1 for no,2 for yes, default:1) -> "
read bk
bk=${bk:-1}
echo -n "input stuID -> "
read stuID
echo -n "input password -> "
read passwd
echo "Select your service:
1. Campus Network Service
2. China Unicom Network Service
3. China Mobile Network Service
4. China Telecom Network Service
5. Campus Intranet
"
read -p "Enter selection [1-5] -> " num
if [ $num -lt 1 ] || [ $num -gt 5 ];then
echo "invalid selection, exit.";
exit;
fi

if [[ $num == 1 ]]; then
service="default"
fi

if [[ $num == 2 ]]; then
service="unicom"
fi

if [[ $num == 3 ]]; then
service="cmcc"
fi

if [[ $num == 4 ]]; then
service="ctcc"
fi

if [[ $num == 5 ]]; then
service="local"
fi
if [ $bk == 2 ]
then
echo -n "input stuID -> "
read stuIDB
echo -n "input password -> "
read passwdB
echo "Select your back service:
1. Campus Network Service
2. China Unicom Network Service
3. China Mobile Network Service
4. China Telecom Network Service
5. Campus Intranet
"
read -p "Enter selection [1-5] -> " num
if [ $num -lt 1 ] || [ $num -gt 5 ];then
echo "invalid selection, exit.";
exit;
fi

if [[ $num == 1 ]]; then
serviceB="default"
fi

if [[ $num == 2 ]]; then
serviceB="unicom"
fi

if [[ $num == 3 ]]; then
serviceB="cmcc"
fi

if [[ $num == 4 ]]; then
serviceB="ctcc"
fi

if [[ $num == 5 ]]; then
serviceB="local"
fi
fi

if [ $bk == 2 ]
then
sed -i '1,8d' UPCNet.sh
sed -i "1i cat=\"$cat\"" UPCNet.sh
sed -i "1i back=\"$bk\"" UPCNet.sh
sed -i "1i service=\"$service\"" UPCNet.sh
sed -i "1i password=\"$passwd\"" UPCNet.sh
sed -i "1i username=\"$stuID\"" UPCNet.sh
sed -i "1i serviceB=\"$serviceB\"" UPCNet.sh
sed -i "1i passwordB=\"$passwdB\"" UPCNet.sh
sed -i "1i usernameB=\"$stuIDB\"" UPCNet.sh
else
sed -i '1,5d' UPCNet.sh
sed -i "1i cat=\"$cat\"" UPCNet.sh
sed -i "1i back=\"$bk\"" UPCNet.sh
sed -i "1i service=\"$service\"" UPCNet.sh
sed -i "1i password=\"$passwd\"" UPCNet.sh
sed -i "1i username=\"$stuID\"" UPCNet.sh
fi
croncmd="sh ${SHELL_FOLDER}"/UPCNet.sh""
cronjob="*/1 * * * * $croncmd"
( crontab -l | grep -v -F "$croncmd" ; echo "$cronjob" ) | crontab -

sed -i "2a ${croncmd}" /etc/rc.local

echo "Auto Install Finished. Enjoy."
rm -- "$0"