C# Web Request Bot's

albaniax

Elite Member
Joined
Aug 5, 2008
Messages
1,637
Reaction score
858
I'm looking for some C# .NET bots, where I can learn from. ( Visual Studio 2008 in school - 2010 at home )

Basically, I have 5 days left for my programming class to finish my project. I choosed to make a few bots, registering Web 2.0 Blogs.

So far, I know how to fill in the input boxes.. that's it.

I would appreciate, if you can post some bot's you have done, where you use the http - WebRequest.

I have to add, that I'm not that experienced at all in C#, so I only need basic stuff, otherwise it would be to obvious that someone else did it.

Let me know,

best regards
Albaniax
 
Why not use a WebBrowser for the automation instead of HttpWebRequest automation? You won't be able to 'fill boxes' without a WebBrowser object, and by then utilizing the MSHTML library to interact with the HTML DOM (document object model).
 
Why not use a WebBrowser for the automation instead of HttpWebRequest automation? You won't be able to 'fill boxes' without a WebBrowser object, and by then utilizing the MSHTML library to interact with the HTML DOM (document object model).

A web server doesn't know if the user 'filled boxes', it just knows HTTP requests. I'd say using HttpWebRequest over the WebBrowser object is a massive performance boost.
 
A web server doesn't know if the user 'filled boxes', it just knows HTTP requests. I'd say using HttpWebRequest over the WebBrowser object is a massive performance boost.

Take this advise.

Although if it's just for a simple school project using a web browser will be much easier and probably the quickest way to achieve your goal.
 
getting a tool like http fox for firefox to understand how the request is made will be a good start. at least to code your own dynamic request analyser but there is few thing to prevent people from botting atm .
 
getting a tool like http fox for firefox to understand how the request is made will be a good start. at least to code your own dynamic request analyser but there is few thing to prevent people from botting atm .

There is nothing that will prevent people botting ever.

Where there is a will, there is usually a way and this is definitely true of programming.
 
I know i'm late with answer ;)

1. Sometimes best way to learn how something works is to reverse engineer it. I download other peoples bots, decompile them and learn from their code. Often code is obfuscated, but even then you can learn how some stuff works.
So, go to download section or to botnet forum, pick up bot you like, download dotpeek software for decompiling, it's free.

2. Search google "site: pastebin.com c# vb.net facebook twitter bot" or something like that, you'll find lot of useful code.

3. Get "HTTP Programming Recipes for C# Bots" book.

If you work with webrequest or sockets, get wireshark or similar software for http analysing.
 
Last edited:
In case anyone else see's this, I have a problem here:

http://pastebin.com/usg8sR4r

Basically, I'm getting an null-reference error when I call the last method and it tries to fill in the Blogname, but not sure why.

Normally it worked, but not after I had put it in another method.

best regards,
Albaniax
 
thanks to user "hatemachine" it's fixed now!

CompletedEvent had to be added, my code was to fast in trying to fill the page, even before it was loaded.
 
getting a tool like http fox for firefox to understand how the request is made will be a good start. at least to code your own dynamic request analyser but there is few thing to prevent people from botting atm .

I have alot of experience in writing C# web scraping applications...let me give you some advice.

1) As osmose01 recommended, get HttpFox, and learn how to use it. Having a basic understanding for the fundamental interaction between how clients/servers interact via HTTP requests will help you greatly.

2) I highly recommend not using the .NET web browser control...way too much overhead involved...learn how to use HttpWebRequest / HttpWebResponse classes, and how to add proper headers for the requests. The headers you see in HttpFox will help you build your GET requests using the HttpWebRequest object.

3) Search for HtmlAgilityPack - its an open source library that makes parsing html for desired data a breeze. You will also need to learn how to use XPath queries, which are pretty easy.

That should give you a good start. If you have any other questions feel free to ask me.
 
Just one question : is it worth time and effort of using socket instead of Httpwebrequest and httpwebresponse? I'm new so I need a right direction to go. Appreciate your answer :)
 
Here is a tip for you start.

Learn how to use HttpWebRequest dont use webbrowser control, thats very very slow and hard to handle if you want to change proxies and other stuffs.

Then use Firebug in Firefox to monitor the requests of the websites that you are trying to automate.
 
Thanks for the suggestions.

I got as a grade a 3 which is C in the U.S. for my (short) project, which is more then enough for me, considering I only worked 4-5 hours on it.

Firebug I already use, HttpFox is a nice tipp as I recently learned how get/set functions work. This would be the next step now.

I choosed Python overall for my programming career, as I focus only to write web bots.

regards
 
Code:
Dim request As WebRequest = WebRequest.Create(SomeWebsite)
            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = "This is a test that posts this string to a Web server."
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
            ' Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded"
            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length
            ' Get the request stream.
            Dim dataStream As Stream = request.GetRequestStream()
            ' Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length)
            ' Close the Stream object.
            dataStream.Close()
            ' Get the response.
            Dim response As WebResponse = request.GetResponse()
            ' Display the status.
            Console.WriteLine(CType(response, HttpWebResponse).StatusDescription)
            ' Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            Console.WriteLine(responseFromServer)
            ' Clean up the streams.
            reader.Close()
            dataStream.Close()
            response.Close()

OR



            Dim request As WebRequest = WebRequest.Create(SomeWebsite)
            ' If required by the server, set the credentials.
            request.Credentials = CredentialCache.DefaultCredentials
            ' Get the response.
            Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
            ' Display the status.
            Console.WriteLine(response.StatusDescription)
            ' Get the stream containing content returned by the server.
            Dim dataStream As Stream = response.GetResponseStream()
            ' Open the stream using a StreamReader for easy access.
            Dim reader As New StreamReader(dataStream)
            ' Read the content.
            Dim responseFromServer As String = reader.ReadToEnd()
            ' Display the content.
            Console.WriteLine(responseFromServer)
            ' Cleanup the streams and the response.
            reader.Close()
            dataStream.Close()
            response.Close()


c&p str8 from microsoft themselves, And thats just the send...

Youll have to make that bot go to a page
parse and load the forms to your program
fill each form item correctly
most likely go fetch captcha image
copy to the local computer
then have the user read and solve it, then add that text to your outgoing packet to send to the server.




so yea its 100xs easier to make a bot with the web browser control.
 
The webbrowser control is shit, the only valid use for it is when the page contains javascript, and even for that there are better solutions like Selenium.
 
The Heaton research web spider is a great way to start. You can even download for free the examples in the book, of course it would be better to buy the ebook in the first place. The book is called "HTTP Programming Recipes for C# Bots", I believe it was mentioned earlier, it has all these recipes that start from the absolute beginner and build up to a complete web spider solution.
 
Back
Top