Created
February 11, 2018 19:06
-
-
Save BigNerd95/fffbd5d7f06d703f531a72afaf979c7c to your computer and use it in GitHub Desktop.
Check and download latest NETGEAR firmware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
from ftplib import FTP | |
import io, re, sys | |
NETGEAR_SERVER = "updates1.netgear.com" | |
class NetgearFtp(): | |
def __init__(self, user=None, pwd=None): | |
self.ftp = FTP(NETGEAR_SERVER) | |
if user and pwd: | |
self.ftp.login(user, pwd) | |
else: | |
self.ftp.login() | |
def cd(self, path): | |
self.ftp.cwd(path) | |
def get(self, name): | |
f = io.BytesIO() | |
self.ftp.retrbinary('RETR ' + name, f.write) | |
f.seek(0, 0) | |
return f.read() | |
def main(model, country, download): | |
nf = NetgearFtp() | |
nf.cd(model) | |
nf.cd(country) | |
# retr info | |
info = nf.get("fileinfo.txt").decode("UTF-16") | |
(fw_name, md5, size) = re.findall("\[Major.\]\r\nfile=(.*)\r\nmd5=(.*)\r\nsize=(.*)\r\n", info)[0] | |
print("Firmware:", fw_name) | |
print("Size:", size, "bytes") | |
print("MD5:", md5) | |
if download: | |
print("Downloading file...") | |
data_data = nf.get(fw_name) | |
with open(fw_name, "wb") as f: | |
f.write(data_data) | |
print("Done!") | |
if __name__ == "__main__": | |
if len(sys.argv) > 2: | |
model = sys.argv[1].lower() | |
country = sys.argv[2].lower() | |
download = False | |
if len(sys.argv) > 3 and sys.argv[3].lower() == "download": | |
download = True | |
main(model, country, download) | |
else: | |
print("Usage:") | |
print("\t", sys.argv[0], "MODEL", "COUNTRY", "[download]") | |
print("\t", sys.argv[0], "dgn2200v4", "ww", "[download]") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment