Results 1 to 3 of 3

Thread: Using Regex To Extract All Ips and ports using Webcontrol vb.net

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2008
    Posts
    18

    Using Regex To Extract All Ips and ports using Webcontrol vb.net

    I have been stumped on this for about 3 weeks now. In the beginning me and my partner have been trying to hit this at the internal angle. only problem is different html tables are constructed different than others. We are needing to extract from multiple pages and sites so we know that Regex will be the best solution. We can use the same script for everything. This is my first time working with Regex, I got it actually extracting the very first ip[proxy].

    I have no idea why it isn't extracting every one on the page. I also have to add the . in between each each octave of the ip. That is weird because I have it in the Regexpession to find the .'s.

    What I'm Needing is for this to basically scan the whole page and grab all the ipsorts and add them to a listbox.

    Here is my code:
    Code:
    Dim request As HttpWebRequest = Nothing
            Dim response As HttpWebResponse = Nothing
            Try
                
                request = DirectCast(WebRequest.Create(("http://nntime.com/proxy-list-01.htm")), HttpWebRequest)
                request.Accept = "*/*"
                request.Method = "GET"
                request.Timeout = &H2710
                request.ReadWriteTimeout = &H2710
                request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)"
                response = DirectCast(request.GetResponse, HttpWebResponse)
                Dim input As String = New StreamReader(response.GetResponseStream).ReadToEnd
                Dim regex2 As New Regex("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b\:(\d+)", RegexOptions.Multiline)
                Dim match2 As Match = regex2.Match(input)
                If match2.Success Then
                    ' Me.TextBox1.Text = match2.Groups.Item(1).Value.Trim
                    Me.TextBox1.Text = TextBox1.Text + match2.Groups.Item(1).Value.Trim & "."
                    Me.TextBox1.Text = TextBox1.Text + match2.Groups.Item(2).Value.Trim & "."
                    Me.TextBox1.Text = TextBox1.Text + match2.Groups.Item(3).Value.Trim & "."
                    Me.TextBox1.Text = TextBox1.Text + match2.Groups.Item(4).Value.Trim & ":"
                    Me.TextBox1.Text = TextBox1.Text + match2.Groups.Item(5).Value.Trim
                End If
                
            Catch exception As Exception
                Trace.WriteLine(("Get Views ex: " & exception.Message))
            Finally
                If (Not response Is Nothing) Then
                    response.Close()
                End If
            End Try
    I need help so bad, this is the first time I have leaned towards a message box but I have no other choice.

    Thanks to who ever will help.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Using Regex To Extract All Ips and ports using Webcontrol vb.net

    i don't know why you have to insert the .

    try this:

    vb Code:
    1. Dim regex2 As New Regex("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b\:(\d+)", RegexOptions.Multiline)
    2. for each match2 As Match in regex2.Matches(input)
    3.      'match found
    4. next

  3. #3
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: Using Regex To Extract All Ips and ports using Webcontrol vb.net

    vb Code:
    1. Dim regex2 As New Regex("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b\:(\d+)", RegexOptions.Multiline)
    2. for each match2 As Match in regex2.Matches(input)
    3.      dim output as string = ""
    4.      output  &= match2.Groups.Item(1).Value.Trim & "."
    5.      output  &= match2.Groups.Item(2).Value.Trim & "."
    6.      output  &= match2.Groups.Item(3).Value.Trim & "."
    7.      output  &= match2.Groups.Item(4).Value.Trim & ":"
    8.      output  &= match2.Groups.Item(5).Value.Trim
    9.      listbox1.items.add(output)
    10. next

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