Skip to content

Instantly share code, notes, and snippets.

@septs
Created June 13, 2023 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save septs/f0d63cb1768ee37efd230afa5a90ddf9 to your computer and use it in GitHub Desktop.
Save septs/f0d63cb1768ee37efd230afa5a90ddf9 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import re
import time
import requests
RE_NONCE = re.compile(r"time=(\d+\.\d+)")
RE_INDEX = re.compile(r"\('(\d+)'\)\"\s*>(.+)</a>")
DOWNLOAD_PAGE = "http://www.irouteros.com/download.php"
def get_name_list():
response = requests.get(DOWNLOAD_PAGE)
return RE_INDEX.findall(response.text)
def get_nonce(session: requests.Session):
response = session.get(DOWNLOAD_PAGE)
matched = RE_NONCE.search(response.text)
if not matched:
return
return matched.groups()[0]
def task(index: int, saved_filename: str):
session = requests.session()
nonce = get_nonce(session)
time.sleep(10)
response = session.get(DOWNLOAD_PAGE, params={
"act": "down",
"id": index,
"time": nonce,
})
with open(saved_filename, "wb") as fp:
fp.write(response.content)
def main():
for index, filename in get_name_list():
print("Started %r" % filename)
task(index, filename)
print("End")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment