This post was imported from an old blog archive, and predates the creation of AdamCaudill.com.
Here’s a simple little example of a dynamic User-Agent in VB.NET. It uses a fairly large list of UA strings, and uses 1 randomly. The code is fairly simple, should be easy to add to any application that needs it.
Module modRandomUA
Dim strUA() As String
Public Sub BuildList()
Dim sr As IO.StreamReader
sr = New IO.StreamReader("browser_list.txt")
strUA = sr.ReadToEnd.Split(ControlChars.CrLf)
sr.Close()
End Sub
Public Function GetUA() As String
Randomize()
Return strUA(Int(Rnd() * strUA.GetLongLength(0))).Trim
End Function
End Module
Module Main
Sub Main()
BuildList()
Dim wcClient As New System.Net.WebClient
Dim bytBuffer As Byte()
wcClient.Headers.Clear()
wcClient.Headers.Set("User-Agent", GetUA())
bytBuffer = wcClient.DownloadData(strURL(i))
End Sub
End Module
You’ll need this as well: UA List