Hallo.
Und zwar würde ich gerne einen Socks 5 Proxy so nutzen können, wie diese Funktion hier:
Hat jemand Tipps, wie man das am schönsten umsetzen kann?
Hab bis jetzt Folgendes:
Und zwar würde ich gerne einen Socks 5 Proxy so nutzen können, wie diese Funktion hier:
VB.NET-Quellcode
- Private Shared Function Req(Site As String, Optional Met As String = "GET", Optional P As String = "") As String
- Dim R As HttpWebRequest = CType(HttpWebRequest.Create(Site), HttpWebRequest)
- With R
- .Proxy = Nothing
- .Method = Met
- .CookieContainer = Containa
- .AllowAutoRedirect = True
- .UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
- .ContentType = "application/x-www-form-urlencoded"
- .Timeout = 20000
- End With
- If Met = "POST" AndAlso P.Length > 4 Then
- R.ContentLength = P.Length
- Using Wr As New StreamWriter(R.GetRequestStream(), System.Text.Encoding.Default)
- Wr.Write(P)
- End Using
- End If
- Using Re As New StreamReader(R.GetResponse.GetResponseStream())
- Return Re.ReadToEnd
- End Using
- End Function
Hat jemand Tipps, wie man das am schönsten umsetzen kann?
Hab bis jetzt Folgendes:
VB.NET-Quellcode
- #Region "SocksStuff"
- Class SocketHelper
- Public Shared Function Connect(T As Integer) As Socket
- Return New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) With {.SendTimeout = T}
- End Function
- Public Shared Function GetResponse(ByVal client As Socket) As String
- Dim num As Integer = 0
- Dim buffer As Byte() = New Byte(1 - 1) {}
- Dim str As String = String.Empty
- Do
- num = client.Receive(buffer)
- str = (str & Encoding.UTF8.GetString(buffer))
- Loop While (num > 0)
- Return str
- End Function
- End Class
- #Region "Socks5Proxy"
- Private cll As Socket
- Private Property Client As Socket
- Get
- Return cll
- End Get
- Set(value As Socket)
- If value.Equals(cll) Then Exit Property
- cll = value
- End Set
- End Property
- Private networkk As NetworkStream
- Private Property connection As NetworkStream
- Get
- Return networkk
- End Get
- Set(value As NetworkStream)
- If value.Equals(networkk) Then Exit Property
- networkk = value
- End Set
- End Property
- Public Function Connect(Host As String, Po As String) As Integer
- Try
- Me.Client = SocketHelper.Connect(8000)
- Me.Client.Connect(Host, Po)
- Me.connection = New NetworkStream(Me.Client)
- Dim writer As New BinaryWriter(Me.connection)
- writer.Write(CByte(5))
- writer.Write(CByte(1))
- writer.Write(CByte(0))
- Dim buffer As Byte() = New Byte(2 - 1) {}
- Me.Client.Receive(buffer)
- If ((buffer(0) = 5) AndAlso (buffer(1) = 0)) Then
- writer.Write(CByte(5))
- writer.Write(CByte(1))
- writer.Write(CByte(0))
- writer.Write(CByte(3))
- Dim bytes As Byte() = Encoding.ASCII.GetBytes(Host)
- writer.Write(CByte(bytes.Length))
- writer.Write(bytes, 0, bytes.Length)
- writer.Write(CByte(0))
- writer.Write(CByte(80))
- Me.connection.Read(buffer, 0, 2)
- Return buffer(1)
- End If
- Catch exception1 As Exception
- Return -1
- End Try
- Return -1
- End Function
- Public Function GetResponse(ByVal encoding As Encoding) As String
- Return New StreamReader(Me.connection, encoding).ReadToEnd.Substring(8)
- End Function
- Public Sub SendByteArray(ByVal data As Byte())
- Me.connection.Write(data, 0, data.Length)
- End Sub
- Public Sub SendString(ByVal str As String)
- Dim bytes As Byte() = Encoding.UTF8.GetBytes(str)
- Me.SendByteArray(bytes)
- End Sub
- #End Region
- #Region "General"
- Private Function Connect(host As String) As Socket
- Dim socket As Socket = SocketHelper.Connect(8000)
- socket.Connect(host, 80)
- Return socket
- End Function
- #End Region
- #End Region