Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects, and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Developer articles
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
wrq2007
ProxyToggle
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
More
items
Files
Expand file tree
main
Breadcrumbs
ProxyToggle
/
toggle_proxy.command
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
49 lines (42 loc) · 1.5 KB
main
Breadcrumbs
ProxyToggle
/
toggle_proxy.command
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
49 lines (42 loc) · 1.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#!/bin/bash
PROXY_IP="192.168.124.26"
PROXY_PORT="8080"
# 自动获取活跃 Wi-Fi 服务名
SERVICE=$(networksetup -listallnetworkservices | grep -m1 "Wi-Fi")
[ -z "$SERVICE" ] && SERVICE="Wi-Fi"
# 临时脚本(避免引号嵌套)
TMPSCRIPT=$(mktemp /tmp/proxy_toggle.XXXXXX.sh)
chmod +x "$TMPSCRIPT"
# 检查代理是否真正有效(非空地址)
WEBPROXY_INFO=$(networksetup -getwebproxy "$SERVICE")
if echo "$WEBPROXY_INFO" | grep -q "Enabled: Yes" && \
echo "$WEBPROXY_INFO" | grep -q "Server: " && \
! echo "$WEBPROXY_INFO" | grep -q "Server: $"; then
# 真正开启 → 关闭
cat > "$TMPSCRIPT" << EOF
#!/bin/bash
networksetup -setwebproxystate '$SERVICE' off
networksetup -setsecurewebproxystate '$SERVICE' off
EOF
MESSAGE="🔒 代理已关闭"
else
# 关闭或空代理 → 开启
cat > "$TMPSCRIPT" << EOF
#!/bin/bash
networksetup -setwebproxy '$SERVICE' '$PROXY_IP' '$PROXY_PORT'
networksetup -setsecurewebproxy '$SERVICE' '$PROXY_IP' '$PROXY_PORT'
EOF
MESSAGE="🌐 代理已开启 → $PROXY_IP:$PROXY_PORT"
fi
# 以管理员权限执行
osascript -e "do shell script \"bash '$TMPSCRIPT'\" with administrator privileges" 2>/dev/null
if [ $? -eq 0 ]; then
echo "$MESSAGE"
else
echo "❌ 操作失败或已取消"
fi
# 清理临时文件
rm -f "$TMPSCRIPT"
# 关闭当前终端窗口(只针对这个 .command 文件的窗口)
osascript -e "tell application \"Terminal\" to close (first window whose name contains \"toggle_proxy.command\")" 2>/dev/null &
exit 0
You can’t perform that action at this time.