第一步 获取光猫MAC地址
这是两种方法
- 看看光猫实体后面的标注
arp -a 192.168.1.1返回的物理地址
第二步 开启Telnet
浏览器输入http://192.168.1.1/telnet?enable=1&key=************
「************」处为光猫的MAC地址,必须全部大写
第三步 登录客户端
telnet 192.168.1.1
PS:电脑若缺少telnet命令,点击这里跳转到开启telnet教程
- name是root
- passwd是
Fh@******
「******」为MAC地址后六位,字母需要大写
第四步 获取超管密码
load_cli factory进入工厂模式show admin_pwd展示超管密码
第五步 登录
- http://192.168.1.1/cu.html
- 输入密码,登录管理员界面
附件
因该光猫重启后会自动更新超管密码,上述步骤只得重新来过
故写出以下Py脚本以便利重复性操作
pip install requests telnetlib3 pyperclip
import re
import subprocess
import requests
import telnetlib3
import time
import pyperclip
def get_mac_address():
"""获取光猫MAC地址"""
print("请选择获取MAC地址的方式:")
print("1. 查看光猫背面的标签")
print("2. 通过arp命令自动获取(需要电脑上开启arp功能)")
choice = input("请输入选择(1/2, 默认2): ")
if choice == '1':
mac = input("请输入光猫背面标签上的MAC地址(格式如AABBCCDDEEFF): ").upper()
return mac.replace(':', '').replace('-', '')
elif choice == '2' or choice == '':
try:
# 执行arp命令获取MAC地址
result = subprocess.run(['arp', '-a', '192.168.1.1'], capture_output=True, text=True)
match = re.search(r'([0-9A-Fa-f]{2}[-:]){5}([0-9A-Fa-f]{2})', result.stdout)
if match:
mac = match.group(0).replace(':', '').replace('-', '')
print(f"获取到的MAC地址: {mac}")
return mac.upper()
else:
print("无法从arp命令中解析MAC地址")
return None
except Exception as e:
print(f"执行arp命令出错: {e}")
return None
else:
print("无效选择")
return None
def enable_telnet(mac_address):
"""开启Telnet服务"""
url = f"http://192.168.1.1/telnet?enable=1&key={mac_address}"
try:
response = requests.get(url, timeout=5)
if response.status_code == 200:
print("Telnet服务已成功开启")
return True
else:
print(f"开启Telnet失败,HTTP状态码: {response.status_code}")
return False
except Exception as e:
print(f"开启Telnet时出错: {e}")
return False
def get_super_password(mac_address):
"""通过Telnet获取超管密码"""
try:
tn = telnetlib3.Telnet("192.168.1.1")
# 登录
tn.read_until(b"(none) login: ")
tn.write(b"root\n")
password = f"Fh@{mac_address[-6:]}".encode('ascii')
tn.read_until(b"Password: ")
tn.write(password + b"\n")
# 进入工厂模式并获取密码
tn.write(b"load_cli factory\n")
time.sleep(1)
tn.write(b"show admin_pwd\n")
time.sleep(1)
# 读取输出
output = tn.read_very_eager().decode('ascii')
tn.close()
# 解析密码 密码格式 为 : 前面是CUAdmin后跟8位数字
match = re.search(r"CUAdmin\d{8}", output)
if match:
password = match.group(0)
print(f"获取到的超管密码: {password}")
return password
else:
print("无法从输出中解析超管密码")
return None
except Exception as e:
print(f"Telnet操作出错: {e}")
return None
def main():
print("光猫超管密码获取工具")
print("=" * 30)
# 第一步:获取MAC地址
mac_address = get_mac_address()
if not mac_address:
print("无法获取MAC地址,程序退出")
return
# 第二步:开启Telnet
if not enable_telnet(mac_address):
print("开启Telnet失败,程序退出")
return
# 第三步和第四步:通过Telnet获取超管密码
super_password = get_super_password(mac_address)
if not super_password:
print("获取超管密码失败,程序退出")
return
# 第五步:提示用户登录
print("\n操作成功!请按以下步骤登录:")
print(f"1. 访问: http://192.168.1.1/cu.html")
print(f"2. 使用超管密码: {super_password} 登录")
print("3. 您现在可以访问管理员界面了")
# 将super_password复制到剪切板里
pyperclip.copy(super_password)
print('4. 管理密码已经复制到剪切板中,请打开浏览器粘贴管理密码进行登录')
if __name__ == "__main__":
main()