Search code examples
c#.netpcappacket-sniffers

captureing URL from packet header


I want to capture streaming video

so I saw URL Getter software and it is good because it gave me the streaming link.

then I tried to make one my self so I used PCAP.net library on vb.net 2010

finally I got the link on that code >>

If packet.Ethernet.IpV4.Tcp.Payload IsNot Nothing Then
                Dim text = Encoding.Default.GetString(packet.Ethernet.IpV4.Tcp.Payload.ToMemoryStream().ToArray())
                Dim match = Regex.Match(text.ToLower(), "(?<=[get|post])\s(?<Path>/.*?)[\?\s].*?http/1\.1.*?host:\s(?<Host>[A-Za-z0-9\-\.]*)", RegexOptions.Singleline)

                    MyStr = match.Groups("Host").Value & match.Groups("Path").Value


            End If

but it doesn't work because I realize that URL Getter get the link with the parameters ..

so My software get the link like this >> http://www.example.com/stream but URL Getter get it like this >> http://www.example.com/stream?ID=0001

so how can I get the link with the paramters ????


Solution

    1. You should only read the first line of the request and parse that
    2. You can use the Uri class to get just some part of the URI.

    However, do note that the query string is a part of the request. You probably don't want to throw it away.