import pygal
from urllib.parse import urlunsplit
WDM = pygal.Table(
columns=2,
default_row=True,
padding=False,
background_color="wheat",
height=1,
font_size=14,
colors={
"default": {
"background": "wheat",
"text": "翻墙梯子"
},
"hover": {
"background": "powderblue",
"text": "翻墙"
},
"selected": {
"background": "lightgrey",
"text": "当前"
}
}
)
# 定义IP地址的转换函数
def convert_ip(ip):
# 将IP地址转换为字符串形式,如192.168.1.1 -> 8.1.1.1
return f"{int(ip[])}.{int(ip[1])}.{int(ip[2])}.{int(ip[3])}"
def urlunsplit_url(url):
# 解析链接,返回真实的IP地址
return urlunsplit(url)
# 定义翻墙梯子的按钮
def create_button(page, label):
button = pygal.Button(page, text=label)
return button
# 创建翻墙梯子
wdm = pygal.Table(
columns=2,
default_row=True,
background_color="wheat",
height=1,
font_size=14,
colors={
"default": {
"background": "wheat",
"text": "翻墙梯子"
},
"hover": {
"background": "powderblue",
"text": "翻墙"
},
"selected": {
"background": "lightgrey",
"text": "当前"
}
}
)
# 设置IP地址转换
wdm.glyph_config['convert_ip'] = convert_ip
wdm.glyph_config['urlunsplit'] = urlunsplit_url
# 定义翻墙梯子的按钮和链接
wdm.add_row(
[
pygal.Label("选择网站(ip:),点击进入翻墙(如果需要)),pygal.PAD_BOTTOM
]
)
# 添加标签和按钮
wdm.add_label("1", "访问网站1")
wdm.add_label("2", "访问网站2")
wdm.add_label("3", "访问网站3")
wdm.add_button(wdm.get_row(1), "选择网站1")
wdm.add_button(wdm.get_row(2), "选择网站2")
wdm.add_button(wdm.get_row(3), "选择网站3")
# 创建翻墙梯子
wdm = pygal.Table(
columns=2,
default_row=True,
background_color="wheat",
height=1,
font_size=14,
colors={
"default": {
"background": "wheat",
"text": "翻墙梯子"
},
"hover": {
"background": "powderblue",
"text": "翻墙"
},
"selected": {
"background": "lightgrey",
"text": "当前"
}
}
)
# 设置IP地址转换
wdm.glyph_config['convert_ip'] = convert_ip
wdm.glyph_config['urlunsplit'] = urlunsplit_url
# 添加标签和按钮
wdm.add_label("1", "翻墙链接:https://example.com")
wdm.add_label("2", "翻墙链接:https://example.com:88")
wdm.add_button(wdm.get_row(1), "翻墙")
wdm.add_button(wdm.get_row(2), "翻墙")
# 创建翻墙梯子并显示
wdm = pygal.Table(
columns=2,
default_row=True,
background_color="wheat",
height=1,
font_size=14,
colors={
"default": {
"background": "wheat",
"text": "翻墙梯子"
},
"hover": {
"background": "powderblue",
"text": "翻墙"
},
"selected": {
"background": "lightgrey",
"text": "当前"
}
}
)
wdm.add_label("1", "网站1")
wdm.add_label("2", "网站2")
wdm.add_button(wdm.get_row(1), "选择网站1")
wdm.add_button(wdm.get_row(2), "选择网站2")
wdm.add_label("3", "网站3")
wdm.add_button(wdm.get_row(3), "选择网站3")
wdm.add_button(wdm.get_row(1), "翻墙")
# 显示翻墙梯子
print(wdm)
# 测试翻墙功能
try:
# 输入网站1的IP地址
ip1 = input("请输入网站1的IP地址:")
print("正在处理...")
if ip1.startswith("192.168.1.1"):
# 处理翻墙
url1 = urlunsplit_url("http://example.com")
wdm.add_label("1", f"翻墙链接:https://{url1}")
else:
print("该IP地址无法翻墙,输入错误。")
except Exception as e:
print(f"错误:{e}")
使用说明:
- 选择网站:在翻墙梯子的顶部-right区域,点击“选择网站1”、“选择网站2”或“选择网站3”来选择要翻墙的网站。
- 输入链接:在底部-right区域,输入网站的IP地址,如果输入的IP地址不是合法的,将会显示错误信息。
- 翻墙:点击“翻墙”按钮(对应翻墙链接的名称)来将链接翻墙。
注意事项:
- 网站翻墙可能需要等待一段时间,具体取决于服务器的响应速度。
- 网站翻墙后的链接格式可能有所不同(某些网站可能使用端口6333来连接)。
- 避免直接复制网络链接或IP地址,建议使用可靠的来源进行翻墙操作。
这个脚本可以作为简单的翻墙梯子实现,如果您需要更多功能或更多的配置选项,可以参考Pygal的文档或进一步调整代码。




