Файл или скрипт для автоматической перезагрузки роутера - VB
Формулировка задачи:
Ребята помогите написать исполняемый файл или рабочий скрипт для автоматической перезагрузки роутера в ОС Windows. Сам не могу. Как делую:
комадная строка-telnet 192.168.1.1 - логин - пароль - перезагрузка - выход
Как приблизительно должен выглядить испоняемый файл для автоматической перезагрузки
telnet 192.168.1.1
задержка 2 секунды
login: admin
задержка 2 секунды
pasword: admin
задержка 2 секунды
>reboot
задержка 3 минуты
выход
Заранее спасибо
Нашел в сети один, но он не работает
Вот код
ya.ru и google.com сервера, которые пингует скрипт для проверки ест ли интернет или нет
user — логин админа роутера или модема – обычно admin
password – пароль админа.
В строчке ‘oShell.Run «telnet.exe 1.1.0.1» вместо 1.1.0.1 прописываем адрес своего роутера (192.168.1.1 например)
В строчке ‘oShell.SendKeys «reload» & chr(13) – reload, это команда, которая перегружает роутер или модем, может отличаться от модели к модели. Посмотрите в документации или методом научного тыка и вставьте ту команду, которая подходит вам – я встречал reload и reboot.
Также скрипт пишет лог файл c:\routerlog.txt
Но не работает пишет ошибки
Листинг программы
- Function PcOnline (strComputer)
- ‘Check if the remote machine is online.
- Dim objPing,objStatus
- Dim TextStream, TimeVar
- Dim fso, tf
- Const ForReading = 1, ForWriting = 2, ForAppending = 8
- Set objPing = GetObject(«winmgmts:{impersonationLevel=impersonate}»)._
- ExecQuery(«select Replysize from Win32_PingStatus where address = ‘» & strComputer & “‘”)
- For Each objStatus in objPing
- If IsNull(objStatus.ReplySize) Then
- PcOnline=False
- ‘Пишем Лог файл
- Set fso = CreateObject(«Scripting.FileSystemObject»)
- If (fso.FileExists(«c:\routerlog.txt»)) Then
- Set tf = fso.OpenTextFile(«c:\routerlog.txt»,ForAppending, True)
- tf.WriteLine(Now() & ” ” & strComputer & ” is down “)
- tf.Close()
- Set fso = Nothing
- Set tf = Nothing
- Else
- Set tf = fso.CreateTextFile(«c:\routerlog.txt»,ForAppending, True)
- tf.WriteLine(Now() & ” ” & strComputer & ” is down “)
- tf.Close()
- Set fso = Nothing
- Set tf = Nothing
- End If
- ‘ Конец Лог файла
- Else
- PcOnline = True
- ‘Wscript.Echo strComputer & ” is responding to a ping ”
- End If
- Next
- Set objPing=Nothing
- Set objStatus=Nothing
- End Function
- Dim fsot, tft
- Const ForReading = 1, ForWriting = 2, ForAppending = 8
- If PcOnline(«[url]www.ya.ru»)_[/url]
- OR PcOnline(«[url]www.google.com»)_[/url]
- Then
- ‘ если статус = 0, пустая строка — другое
- Wscript.Echo «all ok»
- Set fsot = CreateObject(«Scripting.FileSystemObject»)
- Set tft = fsot.OpenTextFile(«c:\routerlog.txt»,ForAppending, True)
- tft.WriteLine(“—————–”)
- tft.Close()
- Set fsot = Nothing
- Set tft= Nothing
- WScript.Quit 0
- Else
- ‘WScript.Echo «Reboot»
- ‘Set oShell = WScript.CreateObject(«WScript.Shell»)
- ‘oShell.Run «telnet.exe 1.1.0.1»
- ‘WScript.Sleep 2000
- ‘oShell.SendKeys «user» & chr(13)
- ‘WScript.Sleep 2000
- ‘oShell.SendKeys «password» & chr(13)
- ‘WScript.Sleep 2000
- ‘oShell.SendKeys «reload» & chr(13)
- ‘WScript.Sleep 2000
- ‘oShell.SendKeys “^({]})q” & chr(13)
- ‘WScript.Quit 255
- End If
- Set fsot = CreateObject(«Scripting.FileSystemObject»)
- Set tft = fsot.OpenTextFile(«c:\routerlog.txt»,ForAppending, True)
- tft.WriteLine(“—————–”)
- tft.Close()
- Set fsot = Nothing
- Set tft= Nothing
Решение задачи: «Файл или скрипт для автоматической перезагрузки роутера»
textual
Листинг программы
- Function PcOnline (strComputer)
- 'Check if the remote machine is online.
- Dim objPing,objStatus
- Dim TextStream, TimeVar
- Dim fso, tf
- Const ForReading = 1, ForWriting = 2, ForAppending = 8
- Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
- ExecQuery("select Replysize from Win32_PingStatus where address = '" & strComputer & "'")
- For Each objStatus in objPing
- If IsNull(objStatus.ReplySize) Then
- PcOnline=False
- 'Пишем Лог файл
- Set fso = CreateObject("Scripting.FileSystemObject")
- If (fso.FileExists("c:\routerlog.txt")) Then
- Set tf = fso.OpenTextFile("c:\routerlog.txt",ForAppending, True)
- tf.WriteLine(Now() & " " & strComputer & " is down ")
- tf.Close()
- Set fso = Nothing
- Set tf = Nothing
- Else
- Set tf = fso.CreateTextFile("c:\routerlog.txt",ForAppending, True)
- tf.WriteLine(Now() & " " & strComputer & " is down ")
- tf.Close()
- Set fso = Nothing
- Set tf = Nothing
- End If
- ' Конец Лог файла
- Else
- PcOnline = True
- End If
- Next
- Set objPing=Nothing
- Set objStatus=Nothing
- End Function
- Dim fsot, tft
- Const ForReading = 1, ForWriting = 2, ForAppending = 8
- If PcOnline("www.ya.ru")_
- OR PcOnline("www.google.com")_
- Then
- ' если статус = 0, пустая строка — другое
- Set fsot = CreateObject("Scripting.FileSystemObject")
- Set tft = fsot.OpenTextFile("c:\routerlog.txt",ForAppending, True)
- tft.WriteLine("-----------------")
- tft.Close()
- Set fsot = Nothing
- Set tft= Nothing
- WScript.Quit 0
- Else
- Set oShell = WScript.CreateObject("WScript.Shell")
- oShell.Run "telnet.exe 192.168.1.1"
- WScript.Sleep 1000
- oShell.SendKeys "user" & chr(13)
- WScript.Sleep 1000
- oShell.SendKeys "pass" & chr(13)
- WScript.Sleep 1000
- oShell.SendKeys "reboot" & chr(13)
- WScript.Sleep 1000
- oShell.SendKeys "^({]})q" & chr(13)
- WScript.Quit 255
- End If
- Set fsot = CreateObject("Scripting.FileSystemObject")
- Set tft = fsot.OpenTextFile("c:\routerlog.txt",ForAppending, True)
- tft.WriteLine("-----------------")
- tft.Close()
- Set fsot = Nothing
- Set tft= Nothing
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д