Question Need help with login to my router Locally

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
hi, this is just a project im working on for myself, now i use to do somthing simlet to this using "VB6" with "winsock raw socket" which was really ideal to use as i liked the way you could program a whole protocol around it, now i'm not sure if the best way is to use "webclient" for this or "Socket.TCPClient" so some guidence would be apriciated, now as i suggest in my code this does not work yet!, my router does not require ssh so its a plain simple login, the bellow code i used here was somthing simler to what i did using "VB6" using the headders and sending the string like so, but from the response headder i can tell it's not logging in at all, i know this the way im doing it is correct as i've done this many times, but is their an easier way or am i sending the string format wrong or somthing?, cheers in advance for any help :).



Imports System.Net
Imports efxControl.efxControl 'Control i made which does some simple efx's

Public Class Login
    Public lConnect As New WebClient
    Public sHost As String = My.Computer.Registry.GetValue _
                      ("HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\services\Tcpip\Parameters\Interfaces\{44B9B5B6-4AC5-4644-9DA7-DF4B4839C41B}" _
                       , "DhcpServer", Nothing)

    Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
        Dim sendData As String

        'For login user and pass which im experimenting with, not working as i can tell
        'lConnect.Credentials = New Net.NetworkCredential(txtName.Text, txtPass.Text)

        'Accumalates data and sends to router for the required login, as of yet not working.
        lConnect.OpenRead("http://" + sHost)
        sendData = "/goform/valogin?loginUsername=" & txtName.Text & "&loginPassword=" & txtPass.Text & "&n=1 HTTP/1.0" & vbCrLf
        sendData += "Accept: */*" & vbCrLf
        sendData += "Accept: text/html" & vbCrLf & vbCrLf
        lConnect.UploadString(sHost, sendData)

        'Displays for headder and page source
        TextBox1.AppendText(lConnect.ResponseHeaders.ToString)
        TextBox1.AppendText(lConnect.DownloadString("http://" + sHost))

        'implemented Functions for efxControl
        'efxFading(90, 1, -1, Me)
        'efxShrinkGrow(200, -1, Me)
    End Sub



    Private Sub Login_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.Text = "Virgin Media Super Hub " & sHost
    End Sub

End Class

 
im pretty new to programming and found socket a bit tricky. i just used the winsock control by downloading mswinsck.ocx and registered it since it has built in events. not sure if thats what you are needing tho.
 
Hi i would use Winsock but as it's not apart of the .NET library also i wouldn't beable to distrobute with my program leagally then that option is out of the window, I'd personally stick with in the .net frame, but was just woundering weather the "Socket's or Webclient" which ever is the best way to go, the pice of code above wont work as i dont have the correct sign in string yet, but thats just alittle bit of packet sniffing and Viewing HTML source, which are simple, but i just wanted to know which is the best way with the .Net Frame and the quickest out of the webclient or socket, if im right then the Socket is more like winsock alot rapid than say Webclient and the HTTP ones, but just needed a handy hint really :D
 
Back
Top