views:

63

answers:

2

I have a piece of hardware with an embedded user control accessed by typing the device's IP Address into a web browser. The device is connected directly to my PC via x-over ethernet cable and static IP's. I need to integrate the control of the device into my C# application.

My thought was to use a packet sniffer to monitor the traffic between my PC and the device while at the same time playing with the device's controls in my web browser. Then finding out which packets that my PC is sending correspond with which controls I am using at that time. Then I can create a class of HTTP or TCP packets in my C# application and send them to the device using the Socket class.

However, I dont have much expereince with network protocols, so when I am using Wireshark to monitor the traffic between my PC and the device, I am not sure where to even start when finding out which packets do what. Does anyone have any ideas? I am open to anything. Thanks!!

EDIT: Its hard to explain exactly what my device is, but its basically an elaborate sensor and typically used in industrial applications, so it could likely be using Modbus, which I am moderately familiar with. Do you know how I can tell which protocol is being used by examining the packets? I noticed (using Wireshark) that the packets being sent from my PC to the device occur in a pattern of 1 HTTP packet, then 5 TCP packets and repeat that same sequence as long as the control is open in my browser. Are there any resources that might give me a better understanding of what is going on?

+2  A: 

Depending on the device it will either be using a variant of the modbus protocol (http://en.wikipedia.org/wiki/Modbus) or something obscure and propriatory.

The best thing to do is to keep sending the same command to the device over and over again until you can recognise similarities in the packets.

If it is propriatory it will probably be something simple like a command/data pair or possibly an XML blob. If you're really unlucky it will be compressed or encoded but unless you're hacking a game or a cash machine this is unlikely.

Asking the manufacturer of the device if they can give you the spec often works as well.

FixerMark
+1 for asking the source
Matt Ellen
+2  A: 

If this is browser controlled, my first thought would be to examine the web pages the device sends to your browser and see what the browser is instructed to do when you manipulate the controls - this seems much easier than messing around with Wireshark.

Is there something I'm missing that makes this impossible (such as a Flash-based control system)? If it's just done with HTML or Javascript, and HTML POST messages or something a bit more sophisticated like Ajax, it should be relatively easy to work out the interface.

Bob Sammers
Good call. I like the idea, but I am completely unfamiliar with javascript, or how I can incorporate a javascript function into a C# application. Is it possible to do without opening a web browser?
Oops, I'd missed the bit where you mentioned using a browser. I'd agree with Bob, take a look at the source of the web pages it's using. You'll probably find it is a simple form with a "post" entry somewhere. take a look at http://msdn.microsoft.com/en-us/library/debx8sh9(v=VS.90).aspx for some information about how to simulate form posts.Even if it is javascript if you're comfortable with C# you should find javascript oddly familar.You don't need to actually incorporate javascript just simulate what it's sending
FixerMark
I think FixerMark has covered everything, but just to be clear, Javascript runs in the browser and all it will do will be to prepare a message to your device's built-in webserver and you need to perform the same function in C#, not include any JS in your program. I think there are only two mechanisms for sending data back to a webserver; HTML Get and Post (and they're quite straight-forward). Although its presence may make the web page more sophisticated, I think the Ajax system I referred to in my answer just uses Post. These can be simulated within C# and FixerMark's link describes how.
Bob Sammers
Thanks for the help!! I ended up creating an instance of IE in the background and using some automation examples I found here: http://www.codeproject.com/KB/cs/automatinginternetexplore.aspx