通过 Sonicwall 自动登录

通过 Sonicwall 自动登录

我们的大学使用 Sonicwall 来屏蔽某些网站,每个学生都可以通过它登录互联网。

很难一次性下载 Linux 发行版 iso 之类的大文件,而且我不想熬夜下载文件。有没有办法让我自动完成这个登录过程。而且我们每三个小时就会断线一次,必须重新登录。

更一般地讲,为了实现这一点,我应该学习哪种脚本语言或技术。我更喜欢 ruby​​,所以如果在 ruby​​ 中可以实现,那么这将是额外的奖励。

答案1

我用 python 编写了一个登录代码,这个代码在我的大学里起作用,

# The selenium.webdriver module provides all the WebDriver implementations. get it online, [I got the module from here][1]
from selenium import webdriver
# The Keys class provide keys in the keyboard like RETURN, F1, ALT etc.
from selenium.webdriver.common.keys import Keys

# here, a instance of Firefox WebDriver is created. You can do it for various browsers
driver = webdriver.Firefox()
# The driver.get method will navigate to a page given by the URL.
#WebDriver will wait until the page has fully loaded (that is, the “onload” event has fired)
# before returning control to your test or script.
# It’s worth noting that if your page uses a lot of AJAX on load then WebDriver may not      know when it has completely loaded. so please be patient
driver.get("https://192.168.20.1/auth1.html")
# The next line is an assertion to confirm that title has “Sonic” word in it: (not really neccesary :p)
# This is used to confirm that the webpage is the right one
assert "Sonic" in driver.title
# we use the 'name' tag to get a handle to the username and password  this finds the appropriate box.
user = driver.find_element_by_name("userName")
passwd = driver.find_element_by_name("pwd")
# use the 'send_keys' function to set the "box's" values to your password and username
user.send_keys("<your username>")
passwd.send_keys("<your password>")
# we sumbit the form
passwd.send_keys(Keys.RETURN)
# we close the window after logging in, the popup which takes care of the 3 hour windows remains open.
driver.close()

现在有很多问题需要解决,

  1. 正如你所见,我使用我导航到的 URL 来登录"https://192.168.20.1/auth1.html" not "https://192.168.20.1/auth.html"这是因为我的大学已经建立了一个框架,基本上我无法使用该网站中的“find_element_by_name”或任何此类功能。这可能因学院而异,请通过阅读您所在学院的源代码进行检查彻底

  2. 我也使用了“userName”和“pwd”作为表单框的名称。这不对你来说这是真实的,你也检查一下。

现在,只有执行此代码时,您才能登录。您可以将其放入循环中,并设置 2.5 小时的时间延迟。我计划让它在后台运行,如果计算机连接到 wifi,脚本将收到通知(我可以在这里使用一些帮助),并且代码可以从对“身份验证页面”的请求开始,如果出现 404 错误,则中断,否则运行代码。(请求库可以帮助解决这些问题)

            #checks for 404 error
            check=requests.head(url)
            if check.status_code==404:
                    break

Python 是一种很棒的语言,你可以进一步研究它,但我认为将它移植到 ruby​​ 并不难,因为 ruby​​ 中也可以使用 selenium。

请随时联系我,因为我正在移植此代码并为 android 等实现更多功能。

答案2

我知道我有点晚了,但我为此制作了一个 chrome 扩展。如果有人需要它...

https://chrome.google.com/webstore/detail/sonicwall-auto-logon/bgcnljfljjkbbaijbanajmpbkhjcmkkh

相关内容