C# - Capturing Network Traffic - c#

I'm interested in capturing network traffic from a specific computer. I am only interested in capturing traffic from the computer that my application is installed on (like Fiddler). Like Fiddler, I want to in particular capture the information shown in the "Web Sessions" portion (ID#, Http Status Code, Protocol, Host, Url, Body size, Content-Type and Process.
While I'm very knowledgable in C#. I have no idea how to actually capture network traffic like this. Can somebody please point me in some sort of direction.
Thank you so much!

NOTE: I'm not 100% sure what you're looking for in terms of a stand-alone application or something to integrate into your application, but my answer will assume you're looking for something to integrate into your app. If not, I'll delete this.
If you're looking for something to integrate into your application that you can essentially enable or disable, you should take a look at FiddlerCore, which is the core functionality that Fiddler uses but can be integrated into stand-alone .NET apps.
The FiddlerCore wiki is here, and it describes the usage pretty well. The sample app is also a good description on how to use FiddlerCore.
Hope this helps. Good luck!

winpcap or one of its .net wrappers is your best option. It is very well documented. If you are doing this in mono, you will need to use libpcap on unix machines. The api's are identical.

Related

Listening to a POS Epson Printer (tm-h6000iii) from a web page

I'm currently attempting to see if it is possible to move a desktop based POS system to an MVC. So far using the Neodynamic Web Print Library (http://www.neodynamic.com/articles/How-to-print-raw-ESC-POS-commands-from-ASP-NET-directly-to-the-client-printer/) I've been able to utilize ESC/P commands to both print from a web page as well as send a drawer kick command.
My next goal is to see if it is at all possible to get data back from the printer. The reason I need to do this is so that I can validate things like the drawer status, slip printer in use, and paper jam etc. So far I've attempted to use the ePOS-print sdk (http://www.novopos.ch/client/EPSON/TM-T88V-i%20und%20Epson%20TM-T70-i/ePOS-Print-API/ePOS-Print_API_UM_E_RevB.pdf) but it appears that it's not possible to utilize it for any EPSON printer that is not classified as a TM-Intelligent printer. I contacted EPSON with this same question and they were very dismissive saying that I would just need to use their ASB commands but I don't see how that could possibly work when sending RAW data from a web page.
I've done a little research into signalr but i didn't find anything that i thought i would be able to use.
I'd prefer to find a way to do this without installing anything on a client's computer but if I have to install some sort of web socket in order to do this it'd be understandable.
Essentially what I need to know is
Is this even possible?
If it is possible, what do you think is the best method to pursue?
I really just need some guidance so that I can focus my research on something that might actually work. Thanks in advance for your time!
You have to install something client side. There are no standards for doing this. Which is the problem that Web-based POSes are wrestling with (such as Vend). The way they get around this is using printers which can talk the web themselves, something like Google cloud print.
I see that Neodynamic DO install something client side, so you could ask them to enhance their software.

Getting input into a process

While talking with a friend over yahoo messenger, I told him would be really cool to make a bot to answer with generic messages when someone starts a conversation. Upon thinking about what I told him, I realized it would be quite interesting to do something like that. The problem is that I don't know much about win32.
So my question is this: how do you 'link' a process to both another one and the windows environment? The goal would be to have an application running in the background which makes some sort of a query to see what windows are opened and when a new yahoo messenger conversation window appears it should send a list of keystroke events to that window.
I could use either C# or VC++ for the programming part and I can use any help: either specific answers or tips that could help me - e.g.: what to google for. So far my google research only came up with some apps/dlls/code that do that for you and some scripting stuff and I'm not exactly searching for that. I want to do all the work myself so I can learn from it.
It seems like you basically want to control other applications.
There are roughly 2 ways to do this on windows
1 - Use the low level windows API to blindly fire keyboard and mouse events at your target application.
The basic way this works is using the Win32 SendInput method, but there's a ton of other work you have to do to find window handles, etc, etc
2 - Use a higher level UI automation API to interact with the application in a more structured manner.
The best (well, newest anyway) way to do this is using the Microsoft UI Automation API which shipped in windows vista and 7 (it's available on XP as well). Here's the MSDN starter page for it.
We use the microsoft UI automation API at my job for automated UI testing of our apps, and it's not too bad. Beware though, that no matter how you chose to solve this problem, it is fraught with peril, and whether or not it works at all depends on the target application.
Good luck
Not quite the same domain as what you're looking for, BUT this series of blog posts will tell you what you need to know (and some other cool stuff).
http://www.codingthewheel.com/archives/how-i-built-a-working-poker-bot
If you really want to learn everything from scratch, then you should use C++ and native WIN32 API functions.
If you want to play a bit with C#, then you should look the pinvoke.net site and Managed Windows API project.
What you'll surely need is the Spy++ tool.
http://pinvoke.net/ seems to be the website you are looking for. The site explains how to use Windows API functions in higher level languages. Search on pinvoke for any of the functions I've listed below and it gives you the code necessary to be able to use these functions in your application.
You'll likely want to use the FindWindow function to find the window in which you're interested.
You'll need the process ID, so use GetWindowThreadProcessId to grab it.
Next, you'll need to use OpenProcess allow for reading of the process's memory.
Afterwards, you'll want to use ReadProcessMemory to read into the process's memory to see what happening with it.
Lastly, you'll want to use the PostMessage function to send key presses to the window handle.
Welcome to the wonderful world of Windows API programming.
Check out Autohotkey. This is the fastest way to do what you want.

Getting started with writing a desktop app that talks to an iPhone

I'm thinking of writing an app to selectively transfer photos/music to and from my iPhone, mostly for fun and personal convenience. However, I'm stuck at the very beginning -- where do I look to find information on how to do this?
Pretty much every link I see talks about developing applications that run on the iPhone, but nothing about desktop app for interfacing with an iPhone.
I'm on Windows (no access to a Mac, but I'll take suggestions for that for when I eventually acquire one), and I'm most familiar with C#, but other languages are definitely an option.
Can anybody offer me a few pointers on getting started? Thanks.
Edit: to clarify further, I don't need information on how to write applications that run ON the iphone. There are plenty of resources out for that. :) What I'm looking for it some pointers on how to "talk" to an iPhone or an iPod through the USB cord, if that's even possible.
Edit #2: I found libmobiledevice library that effectively does what I'm talking about on Linux. I don't think I'm too keen on attempting to port it over to Windows, though. :)
I found what I was looking for: SharePodLib. Thanks, everyone.
I recommend and have used the following options:
Option 1:
Run a small and light webserver in the iPhone and of course, use HTTP to transfer. I recommend mongoose websever, i've tried it with very simple and very heavy load. Also here, you can find an actual drag and drop project to deploy this webserver in the iPhone.
Option 2:
Use something like Bonjour, this is something very useful if you want the "smart" discovery of your device in the network, maybe for opportunistic peer discovery. You can check here and here, to understand how to get bonjour to run in the iPhone and use it to exploit discovery and sharing.
Hope it helps!!
Unfortunately, there's no no way to sync an iPhone app with a Mac app over USB, at least in the current SDK. As already stated, you'll have to either sync over HTTP or use the local network. You might want to check out ZSync, a Cocoa library for bonjour syncing (I haven't used it, and it's in early development stages, but it looks interesting).
Unfortunately there is no officially sanctioned method to do what you describe. In Apple's view the only application that should have visibility of that information is iTunes. There are applications out there that appear to be able to do this, but I suspect they have reverse engineered the USB protocol and are thus open to being locked out if the protocol changes.

Wiimote example programs

I'd like to use the Wiimote (accelerometers, gyroscopes, infrared camera, etc, etc, etc) on various applications.
It's a bluetooth device, and I know others have connected it to their computer.
What's the easiest way to start using it in my software - are there libraries for C#, for instance?
I want my software to be usable and easily installable - what's the current easiest way to connect a wiimote to the computer? Can I make that process part of my software installation?
-Adam
Have you seen Johnny Chung Lee's 'Procrastineering' Blog? He's written a lot on the subject of using wii remotes and has some fantastic demonstration videos. [Edit] I just found out Mr Lee did a TED talk which gives a good introduction to the stuff he's done too...
There's a wealth of information over on Wiibrew.org - check out their Wiimote Library page for some other APIs if you want to look beyond c#. As an avid Python fan, I'm quite curious to have a play with the pyWiimote library :-)
Coding4Fun had a managed C# library up that would allow you to interface with it but it seems their site is down right now. Though I think they used the Robotics Studio so that may be a place to start.
Found it... http://www.codeplex.com/WiimoteLib
Oh and I forgot to post a link to these videos I saw quite some time ago. http://www.cs.cmu.edu/~johnny/projects/wii/
If you use WiimoteLib (from Coding4Fun as mentioned in another answer), there is an example application called WiimoteTest. This tests all of the Wiimote inputs and outputs, including for multiple Wiimotes at the same time, so it is a good starting point for your own Wiimote code as it gives you an example of how to do pretty much anything you would want to.
For the second part of your question, connecting the Wiimote to the computer is pretty much the same as connecting any other Bluetooth device. I don't know that it would be very suitable to have this done at installation as it is likely to be connected and disconnected a lot, especially since the Wiimote will turn itself off if not used for a while. However, it's pretty much a matter of following a standard Windows wizard to connect to it, so it's not too hard. This assumes you have a Bluetooth driver that will work with the Wiimote - more information on that is available at the Coding4Fun website. It worked for me with the default driver that already came with my laptop but if it doesn't for you, the one they recommend is BlueSoleil.
what's the current easiest way to
connect a wiimote to the computer?
I not found solution for connect wiimote within my software, you have to connect manually into Windows, but on Windows register bluetooth device it very take time, Try Toshiba bluetooth stack it more convenient.

Where can I get started writing a media server in C# like PlayOn

Where can I get started writing a media server in C# like PlayOn
http://www.themediamall.com/playon
UPDATE:
I have learned that PlayOn is a is a DLNA/UPnP media server but I am still looking for C# example implementation of this type of server. I am placing a bounty and will award it if you can point me to some sample code that I can use to server photos and/or video content to a media client like XBOX 360, Playstation 3, Media Center, or Media Center Extenders
After more research I have learned that PlayOn is a is a DLNA/UPnP media server. There is not lots of information on it but there are a few. If anyone can reference an example that would be awesome.
here some links I found after discovering I was looking for DLNA/UPnP
Creating a DLNA server/service in VB.NET
C# UPNP/DNLA Media Server Library
This question may also help point you in the right direction.
Specifically the accepted answer point to the Platinum UPnP library. Whilst it's a C++ library, it looks promising and i'm sure it could be integrated with a C# solution or at least give you ideas for your own implementation.
My recommendation would be not to write you own server for the reason that Windows Media Services - which is a great FREE streaming server from Microsoft is available already. It focuses on the heavy lifting of how do you stream, formats etc... is well documented and understood which makes deployment easier. Your focus could then be on the areas it sucks at, which is client front end - i.e. a nice web or Silverlight interface, maybe an RSS feed of videos. This shouldn't be hard as the server API and how to write code against it is well documented.
XNA Studio?
Perhaps have a look at the codebase for Media Portal
Here is the developer page
http://www.team-mediaportal.com/contribute_to_mediaportal.html
There is also a media sharing library on code plex that might help
http://www.codeplex.com/blueportal
Here's a couple of things to look into:
/whsUpnp360
UPnP MediaServer using Intels SDK for Windows Home Server and Xbox 360 (written in C#)
http://www.mperfect.net/whsUpnp360/
UPnP library for C#?
http://bytes.com/groups/net-c/741142-upnp-library-c

Categories