Results 1 to 2 of 2

Thread: Proxy Server

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Proxy Server

    Hey all,

    I recently Ported this C# proxy across to VB.net but I am having the same problems I did in C#... It dosn't fully load a web page (and some dont even load).

    VB Code:
    1. Imports System.Threading
    2. Imports System.Net.Sockets
    3. Imports System.Net
    4. Imports System.Text
    5.  
    6. Module Module1
    7.  
    8.     Private attempts As Integer = 0
    9.  
    10.     Private MAXFILESIZE As Integer = 20 * 1024 * 1024
    11.     'MB
    12.     Sub Main(ByVal args As String())
    13.  
    14.         Dim t As New Thread(New ThreadStart(AddressOf AcceptSockets))
    15.  
    16.         t.Start()
    17.  
    18.     End Sub
    19.  
    20.     Private Sub AcceptSockets()
    21.  
    22.         Dim flag As Integer = 0
    23.  
    24.         Try
    25.  
    26.  
    27.             Dim listener As New TcpListener(IPAddress.Any, 9876)
    28.  
    29.             listener.Start()
    30.  
    31.             While True
    32.  
    33.  
    34.                 'Accepts connection to IE to get GET command
    35.  
    36.                 Dim sock As Socket = listener.AcceptSocket()
    37.  
    38.                 sock.DontFragment = True
    39.  
    40.                 Dim fromIE As [Byte]() = Nothing
    41.  
    42.                 fromIE = New [Byte](MAXFILESIZE - 1) {}
    43.  
    44.                 flag = 1
    45.  
    46.                 'Recievies the GET command from IE
    47.  
    48.                 Dim length As Integer = sock.Receive(fromIE, 0, MAXFILESIZE, SocketFlags.None)
    49.  
    50.                 Dim [GET] As [Byte]() = New [Byte](length - 1) {}
    51.  
    52.                 For i As Integer = 0 To length - 1
    53.  
    54.  
    55.                     [GET](i) = fromIE(i)
    56.                 Next
    57.  
    58.                 flag = 2
    59.  
    60.                 'Translates Bytes -> string
    61.  
    62.                 Dim input As [String] = Encoding.ASCII.GetString([GET])
    63.  
    64.                 flag = 3
    65.  
    66.                 Dim outServer As New TcpClient()
    67.  
    68.                 'Extracts destination server from GET command
    69.  
    70.                 Dim ServerIP As [String] = getReceivingIP(input)
    71.  
    72.                 flag = 4
    73.  
    74.                 'Connects to Destination Server
    75.  
    76.                 outServer.Connect(ServerIP, 80)
    77.  
    78.                 flag = 5
    79.  
    80.                 'Retrieves Stream and writes entire
    81.  
    82.                 Dim stream As NetworkStream = outServer.GetStream()
    83.  
    84.                 stream.Write(fromIE, 0, length)
    85.  
    86.                 flag = 6
    87.  
    88.                 'Recieve response containing webpage and pictures from
    89.  
    90.                 'Destination server
    91.  
    92.                 Dim fromServer As Byte() = Nothing
    93.  
    94.                 fromServer = New Byte(MAXFILESIZE - 1) {}
    95.  
    96.                 If stream.CanRead Then
    97.  
    98.  
    99.                     length = stream.Read(fromServer, 0, fromServer.Length)
    100.  
    101.                     flag = 7
    102.  
    103.  
    104.                     sock.Send(fromServer, length, SocketFlags.None)
    105.                 End If
    106.  
    107.                 attempts = 0
    108.  
    109.  
    110.                 sock.Close()
    111.  
    112.             End While
    113.  
    114.         Catch ex As Exception
    115.             'Connection Errors
    116.             Console.WriteLine(ex.ToString())
    117.  
    118.             Console.WriteLine()
    119.  
    120.             Console.WriteLine("Last Successful Flag at: " & flag)
    121.  
    122.             '3 consecutive failed attempts before stopping connection.
    123.  
    124.             If System.Threading.Interlocked.Increment(attempts) <= 3 Then
    125.  
    126.  
    127.                 Console.WriteLine("Attempts: " & attempts)
    128.  
    129.                 Console.WriteLine()
    130.  
    131.  
    132.                 AcceptSockets()
    133.             End If
    134.  
    135.             'Infinite loop so any errors remain
    136.  
    137.             'On screen to be read
    138.  
    139.             While True
    140.  
    141.             End While
    142.         End Try
    143.  
    144.     End Sub
    145.  
    146.     Private Function getReceivingIP(ByVal input As [String]) As [String]
    147.  
    148.         'Example of Input:
    149.  
    150.         'GET http://www.google.com/ HTTP/1.1
    151.  
    152.         'Accept: image/gif ....
    153.  
    154.         '.
    155.  
    156.         '.
    157.  
    158.         '.
    159.  
    160.         'Host: www.google.com
    161.  
    162.         '...
    163.  
    164.         'This returns www.google.com from host line
    165.  
    166.         'Find beginning of host in host line
    167.  
    168.         Dim begin As Integer = input.IndexOf(vbCr & vbLf & "Host: ") + 8
    169.  
    170.         'find ending of host
    171.  
    172.         Dim [end] As Integer = input.IndexOf(vbCr & vbLf, begin)
    173.  
    174.         Dim length As Integer = [end] - begin
    175.  
    176.         'get host
    177.  
    178.         Dim url As [String] = input.Substring(begin, length)
    179.  
    180.         Console.WriteLine(url)
    181.  
    182.         Console.WriteLine()
    183.  
    184.         'return host
    185.  
    186.         Return url
    187.  
    188.     End Function
    189.  
    190. End Module

    As you can see in the following picture it dosn't completely load VBforums.com:

    As you can see above the page just stops and in the source code you can tell the page didn't completely load

    What is going on??

    Thanks for any help

    -Josh

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Apr 2010
    Posts
    121

    Re: Proxy Server

    No one? What I really need is a packet editor... anyone offering?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width