Code to telnet to an Actiontec DSL Gateway and reboot it if
there is no internet connection.
Create a new Windows Service and paste this code into Service1.vb
Public
Class
RebootActiontec
Protected
Overrides
Sub OnStart(ByVal
args() As
String)
' Add code here to
start your service. This method should set things
' in motion so your service can do its work.
clt =
New
System.Net.Sockets.TcpClient
MyTimer = New
System.Threading.Timer(AddressOf
MyTimer_Elapsed, Nothing,
300000, 300000) '5 minutes
End
Sub
Protected Overrides
Sub OnStop()
' Add code here to
perform any tear-down necessary to stop your service.
MyTimer.Change(System.Threading.Timeout.Infinite,
System.Threading.Timeout.Infinite)
MyTimer.Dispose()
clt = Nothing
stm =
Nothing
End Sub
Dim WithEvents
MyTimer As
System.Threading.Timer
Dim clt
As
System.Net.Sockets.TcpClient
Dim stm
As
System.Net.Sockets.NetworkStream
Private Function
RebootActiontec() As
String
Dim resp
As
String
Try
clt =
New
System.Net.Sockets.TcpClient
clt.Connect("192.168.0.1",
23)
'This is the IP Address of your DSL Gateway.
stm = clt.GetStream
resp = GetActiontecResponse()
Threading.Thread.Sleep(1000)
resp &= SendToActiontec("AdminID")
'Enter your own Admin ID here
Threading.Thread.Sleep(1000)
resp &= SendToActiontec("AdminPwd")
'Enter your own Admin Password here
Threading.Thread.Sleep(1000)
resp &= SendToActiontec("cd
sbin")
Threading.Thread.Sleep(1000)
resp &= SendToActiontec("reboot")
Threading.Thread.Sleep(1000)
stm.Close()
clt.Close()
Catch
ex As Exception
resp = ex.Message
End
Try
Return resp
End
Function
Private Function
SendToActiontec(ByVal
msg As
String)
As
String
' Send message to
Actiontec
Dim
sendBytes As
Byte() =
System.Text.Encoding.ASCII.GetBytes(msg & vbCr)
stm.Write(sendBytes, 0, sendBytes.Length)
Return
GetActiontecResponse()
End
Function
Private Function
GetActiontecResponse() As
String
Dim trm()
As
Char = {ControlChars.NullChar}
Dim
bytes(clt.ReceiveBufferSize) As
Byte
stm.Read(bytes, 0,
CInt(clt.ReceiveBufferSize))
Dim
returndata As
String =
System.Text.Encoding.ASCII.GetString(bytes)
Return
returndata.Trim(trm)
End
Function
Private Sub
MyTimer_Elapsed(ByVal
state As
Object)
'The following line can use any
Internet IP address. I used the IP Address shown under
'"Gateway:" on the Actiontec's "Current Status" Page.
Dim
ping As
Boolean =
My.Computer.Network.Ping("67.42.227.193")
If
ping = False
Then
EventLog.WriteEntry(RebootActiontec)
End
If
End Sub