Skip to content

Instantly share code, notes, and snippets.

@ouyen
Last active February 19, 2024 17:15
Show Gist options
  • Save ouyen/08c7895dde30bc602d92f1a0d4f35c8c to your computer and use it in GitHub Desktop.
Save ouyen/08c7895dde30bc602d92f1a0d4f35c8c to your computer and use it in GitHub Desktop.
pkuvpn.sh
echo PASSWORD | openconnect --script-tun --script "ocproxy -D 7900 -g -k 15" --protocol=pulse vpn.pku.edu.cn -u 1900014514 --reconnect-timeout 60 --passwd-on-stdin
@ouyen
Copy link
Author

ouyen commented Jan 5, 2023

sudo apt install openconnect ocproxy

@ouyen
Copy link
Author

ouyen commented Jan 5, 2023

1900014514 -- 学号
PASSWORD -- 密码

@ouyen
Copy link
Author

ouyen commented Jan 5, 2023

systemd service

view /etc/systemd/system/pkuvpn.service

[Unit]
Description=Connect to my VPN
After=network.target

[Service]
Type=simple
ExecStart=/bin/sh -c 'echo PASSWORD | openconnect --script-tun --script "ocproxy -D 7900 -g -k 15" --protocol=nc vpn.pku.edu.cn -u 1900014514 --reconnect-timeout 60 --passwd-on-stdin'
Restart=always

[Install]
WantedBy=multi-user.target
sudo su
systemctl daemon-reload
systemctl enable pkuvpn.service
systemctl start pkuvpn.service

@Rainshaw
Copy link

Dockerfile:

FROM ubuntu:22.04

RUN apt-get update && \
  apt-get install -y \
  ocproxy openconnect && \
  rm -rf /var/lib/apt/lists/*

CMD ["/bin/bash", "-c", "echo $PASSWORD | openconnect --script-tun --script \"ocproxy -D 7900 -g -k 15\" --protocol=nc vpn.pku.edu.cn -u $PKUID --reconnect-timeout 60 --passwd-on-stdin"]

@Mickychen00
Copy link

Hi! Thanks a lot for this gist script.
But in recent days, I have found that it doesn't work. I didn't change anything. Are there something changed?

Got HTTP response: HTTP/1.1 302 Moved
GET https://vpnu.pku.edu.cn/dana-na/auth/url_izFvvX9SGEKBRRI9/welcome.cgi?p=failed
frmLogin
3 consecutive empty forms, aborting loop
Failed to complete authentication

@ouyen
Copy link
Author

ouyen commented Jan 29, 2024

change protocol from nc to pulse, and need to build openconnect form source code : work with v9.12, but failed with 8.20-1 ( ubuntu 22.04 apt)

@Mickychen00
Copy link

Does this solution work on MacOS? For me, I haven't ever tried to build tools like openconnect by myself before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment