Portforward Via POST
Portforward Via POST
Portforward Via POST
Portforward Via POST
Portforward Via POST
Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST
Portforward Via POST Portforward Via POST
Portforward Via POST
Go Back  Xtreme Visual Basic Talk > > > Portforward Via POST


Reply
 
Thread Tools Display Modes
  #1  
Old 08-08-2008, 05:49 PM
AgentSmithers AgentSmithers is offline
Contributor
 
Join Date: Jan 2005
Location: SOCal
Posts: 492
Angry Portforward Via POST


Ok I have a WRT54G and its not version 1.00.9 , anywho I all I want to do is login and send POST to portforward but I always get a Violation, Anyone know the correct way to do this? Here are my 3 tryes and all failed =(
Help?! =D

Code:
Module Module1

    Sub Main()
        Post3()
        Console.ReadKey()
        Exit Sub
        Dim MyWebRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://192.168.1.1/PortRange.tri") '"http://192.168.2.1/index.asp")
        MyWebRequest.Credentials = New System.Net.NetworkCredential("admin", "admin")
        MyWebRequest.AllowAutoRedirect = True
        Try
            Dim MyResponse As System.Net.WebResponse = MyWebRequest.GetResponse()
            Dim MySR As System.IO.StreamReader = New System.IO.StreamReader(MyResponse.GetResponseStream)
            Dim Str As String = MySR.ReadLine

            While Not MySR.EndOfStream
                Console.WriteLine(Str)
                Str = MySR.ReadLine
            End While
        Catch ex As Exception
            If ex.Message = "The remote server returned an error: (401) Unauthorized." Then
                Console.WriteLine("Access Denied")
            Else
                Console.WriteLine(ex.Message)
            End If
        End Try



        Console.WriteLine("Done")

        Console.ReadKey()
    End Sub

    Sub WebRequester()
        Dim URL As String = "http://www.csharpcorner.com/default.asp"
        Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(URL)
        Dim response As System.Net.WebResponse = request.GetResponse()
        Dim reader As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
        Dim str As String = reader.ReadLine()
    End Sub

    Sub Post()
        Dim oNameValues As New System.Collections.Specialized.NameValueCollection
        oNameValues.Add("Action", "Apply")
        oNameValues.Add("name9", "RDP")
        oNameValues.Add("from9", "3389")
        oNameValues.Add("to9", "3390")
        oNameValues.Add("pro9", "both")
        oNameValues.Add("ip9", "124")
        oNameValues.Add("enable9", "on")

        Dim thePage As Byte()
        Dim MyWebClient As New System.Net.WebClient

        MyWebClient.Headers.Set(Net.HttpRequestHeader.Host, "192.168.1.1")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.AcceptEncoding, "gzip,deflate")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.KeepAlive, "300")
        MyWebClient.Headers.Set(Net.HttpRequestHeader.Connection, "keep-alive")
        'MyWebClient.Headers.Add(Net.HttpRequestHeader.Referer, "http://192.168.1.1/Forward.htm")
        MyWebClient.Headers.Add(Net.HttpRequestHeader.Authorization, "Basic " & Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("admin:admin")))
        MyWebClient.Headers.Add(Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded")
        
        Try
            'thePage = (MyWebClient.DownloadData("http://192.168.1.1/Forward.htm"))
            'Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(thePage))
            thePage = MyWebClient.UploadValues("http://192.168.1.1/PortRange.tri", "POST", oNameValues)
            Console.WriteLine(System.Text.ASCIIEncoding.ASCII.GetString(thePage))
        Catch exa As System.Net.WebException
            Console.WriteLine("WebException error")
            Console.WriteLine(MyWebClient.Headers.ToString)
        Catch ex As Exception
            Console.WriteLine("error")
        End Try

    End Sub

    Sub Post2()

        Dim MyWebRequest As System.Net.HttpWebRequest
        MyWebRequest.Credentials = New System.Net.NetworkCredential("admin", "admin")
        MyWebRequest.AllowAutoRedirect = True
        MyWebRequest.ProtocolVersion = New Version(1, 1)
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.UserAgent, "192.168.1.1")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.AcceptLanguage, "en-us,en;q=0.5")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.AcceptEncoding, "gzip,deflate")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.AcceptCharset, "ISO-8859-1,utf-8;q=0.7,*;q=0.7")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.KeepAlive, "300")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.Connection, "keep-alive")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.Referer, "http://192.168.1.1/Forward.htm")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.Authorization, "Basic " & Convert.ToBase64String(System.Text.Encoding.Default.GetBytes("admin:admin")) & vbCrLf)
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.ContentType, "application/x-www-form-urlencoded")
        MyWebRequest.Headers.Add(Net.HttpRequestHeader.ContentLength, "application/x-www-form-urlencoded")
        Try
            Dim MyResponse As System.Net.WebRequest = System.Net.WebRequest.Create("HTTP://192.168.1.1/PortRange.tri")
            'Dim MySR As System.IO.StreamReader = New System.IO.StreamReader(MyResponse.GetResponseStream)
            'Dim Str As String = MySR.ReadLine

            'While Not MySR.EndOfStream
            'Console.WriteLine(Str)
            'Str = MySR.ReadLine
            'End While
        Catch ex As Exception
            If ex.Message = "The remote server returned an error: (401) Unauthorized." Then
                Console.WriteLine("Access Denied")
            Else
                Console.WriteLine(ex.Message)
            End If
        End Try



        Console.WriteLine("Done")

        Console.ReadKey()
    End Sub

    Sub Post3()
        'System.Net.HttpWebResponse()
        Dim MyWebRequest As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://192.168.1.1/PortRange.tri")
        MyWebRequest.Credentials = New System.Net.NetworkCredential("admin", "admin")

        MyWebRequest.Method = "POST"

        Dim Mypost As String = "action=Apply&name9=RDP&from9=3389&to9=3390&pro9=both&ip9=124&enable9=on"
        Dim Data() As Byte = System.Text.ASCIIEncoding.ASCII.GetBytes(Mypost)
        Try

            MyWebRequest.ContentType = "application/x-www-form-urlencoded"
            MyWebRequest.ContentLength = Data.Length
            Dim MySW As System.IO.StreamWriter = New System.IO.StreamWriter(MyWebRequest.GetRequestStream)
            MySW.Write(Data)

            Dim MyResponse As System.Net.WebResponse = MyWebRequest.GetResponse()
            Dim MySR As System.IO.StreamReader = New System.IO.StreamReader(MyResponse.GetResponseStream)
            Dim Str As String = MySR.ReadLine

            While Not MySR.EndOfStream
                Console.WriteLine(Str)
                Str = MySR.ReadLine
            End While
        Catch ex As Exception
            If ex.Message = "The remote server returned an error: (401) Unauthorized." Then
                Console.WriteLine("Access Denied")
            Else
                Console.WriteLine(ex.Message)
            End If
        End Try

        Console.WriteLine("Done")

        Console.ReadKey()
    End Sub

    Sub upnp()

    End Sub
End Module
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Portforward Via POST
Portforward Via POST
Portforward Via POST Portforward Via POST
Portforward Via POST
Portforward Via POST
Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST Portforward Via POST
Portforward Via POST
Portforward Via POST
 
Portforward Via POST
Portforward Via POST
 
-->