GetExtendedUdpTable and Remote Ip Address - c#

I've got some c# code that is mapping processes to ip addresses, I'm basically trying to write some software that will look at a process and give me the ip address so that I can write a monitor that will allow friends to find be in games.
When running my application though it detects that a game process has a UDP connection but I can't seem to get the ip address.
I've run a packetsniffer and 78.111.229.123:32000 shows up on the router/gateway but it's not showing in my application.
Any ideas to get me up and running?

How are you setting up the socket in the game application? Can you post an example of your socket setup code?
Are you using the wildcard address and port when creating the socket? I'm guessing that if your game application doesn't bind to a specific IP address and port explicitly that may be the source of your problem.
Another question: are you trying to detect the local IP address, remote IP address or both?
If you're trying to detect the remote IP address this may be impossible unless the game application is using what's known as connected UDP sockets. This is where the client application calls connect on the UDP socket to create an association between the local and remote sockets in the underlying OS. This has certain advantages and drawbacks as listed in the above link.
Edit
Take a look at this SO post: PID from socket number on Windows?
This pretty much confirms what I thought - unless the game is using connected UDP sockets then the only way you'll be able to get the remote address is via packet sniffing.
Start up the game and run netstat -ap UDP - if you see that there aren't any remote addresses listed then that would confirm the above suspicion.

Related

How to get remote ip address and port from active udp connection?

I'm working on a graphical windows application. So solutions on c++ and c# are prefered.
For my application, I need to get the remote address and port from active udp connection from a specific process.
I tried IP Helper API but the methods for UDP don't give remote address and port.
I've already see these posts Get Destination Ip/Port of active udp Connection? and Remote address of active UDP connections in Windows using IP Helper.
I understand why IP Helper can't do the job (udp is connectionless and need to capture packet) but I found nothing concrete how to accomplish that.
Have you a solution ready to use or something close to it?
As you have already discovered, UDP is connectionless, so the OS doesn't track remote party info, like it does for TCP. Unlike a TCP socket, a UDP socket can communicate with multiple remote parties at a time, where sendto() specifies a destination ip/port, and recvfrom() reports a sender's ip/port.
I understand why IP Helper can't do the job (udp is connectionless and need to capture packet) but I found nothing concrete how to accomplish that.
You need to use a packet capture library, such as libpcap, and manually keep track of the ips/ports of outgoing packets you see.

client/server chat program in C#/winforms IP address issue

I am trying to make a winforms client/server chat application. I already have a client and a server, both are working fine, i can log in, send messages, etc .. The problem is that it only works if i connect to my local IP. When i try to run the program with my external IP, i get the following error:
"The requested address is not valid in its context".
In other words, i can run the server on my own computer, start up (for example) 3 clients and let them connect to the running server. This basically means that i'm talking to myself. What im trying to do is to run the chat server on my computer, and let other people run the client-program and connect to the server through the internet.
this is the part where i get an error when i enter my external IP:
public void StartListening()
{
// Get the IP of the first network device, however this can prove unreliable on certain configurations
IPAddress ipaLocal = ipAddress;
// Create the TCP listener object using the IP of the server and the specified port
tlsClient = new TcpListener(ipaLocal, 50702);
// Start the TCP listener and listen for connections
tlsClient.Start(); <--- THINGS GO SOUTH HERE
// The while loop will check for true in this before checking for connections
ServRunning = true;
// Start the new tread that hosts the listener
thrListener = new Thread(KeepListening);
thrListener.Start();
}
im not sure if what i'm trying to do is possible? i can't imagine it is, but i kinda dont know how to proceed with this. I'm new to network programming so any help will be appreciated.
kind regards,
Jane
Jane,
I think your issue is with your IP address setup. This is a network connection problem. You need external IP address so that outside clients can contact your PC. You need more advanced networking. The IP address provided from you ISP is used for domestic uses. You need specialized public IP address so that clients can find you outside of the firewall. This is networking/ISP/external IP issue.
Your server application needs to listen to incoming connections on a specified port, on a specified locally installed NIC. That is why TcpListener always needs to be created using a local IP address: because it only cares which NIC (if you have multiple installed) it should use.
The MSDN page for TcpListener also states it explicitly:
TcpListener Constructor (IPAddress, Int32) Initializes a new instance of the TcpListener class that listens for incoming connection attempts on the specified local IP address and port number.
External IP address is completely irrelevant to a TCP/IP server. You can have numerous routers and network devices along the way, which can then forward incoming connections to your machine.
Just do make sure that your firewall and router are configured properly to allow incoming connections on a specified port. To do that, start your TCP/IP server to open the port, and then use a service like CanYouSeeMe to see if server can be reached from outside.
Regarding your comment (this can prove unreliable on certain configurations), it's obviously "unreliable" when you think about it: a laptop can easily have an Ethernet network controller with a completely different IP address than a Wifi network adapter. Your server app should allow the user to select which IP address to use, instead of picking the first address it gets.

C# and ActiveSync communication / open and read files

I have a device connected to a host computer through cradle usb. Now, I'm just wondering if I could use C# sockets to communicate with the device (ie device sending data, host computer processing it then replying back to the device). How can I accomplish this? by that, what ip address etc etc.. do I have to change so that it would connect cause I have the sockets working on wireless. If not, then is there a way to connect to the device, open and read a file (a text document to be more specific) from the device to my host application.. any ideas?
Thanks! :)
Depending on your target device, when you connect via ActiveSync it likely makes a local RNDIS network connection between teh two devices. You can resolve "ppp_peer" as the partner's network name instead of trying to use a hard-coded IP address (IIRC the IP is different on XP than on Vista).
Be aware that it's not a full connection. TCP packets gets passed through, but things like ICMP do not.
Of course, this just gives you a socket connection, just like if you were to connect between two PCs. It's not going to allow you to do file system operations unless you have an app on the other side listening for commands. If you want that type of thing, Microsoft provides the Remote API (RAPI) interface (wrapped in managed code here)for a lot of basic commands, and it can be extended (with C) to do anything you'd like.

how can I find the remote address of a continuous UDP stream

For those of you who play MW2 on the PC you know it is plagued by hackers and cheaters. I would like to create a solution where the host of a multi player game can selectively firewall out a cheater.
The problem I am running into is I do not know how to locate remote IPs that are sending or receiving UDP packets.
Netstat will only show the listeners on my local machine.
IPGlobalProperties does not have any methods I can use either as UDP is connectionless.
How can I go about finding remote IPs of UDP packets?
I would like to code a solution using C#.
You'll want to write a network sniffer to start with, see this CodeProject example.
here is my source code for the admin tool i made, vac will ban you for it
it uses winpcap to read the game network traffic, and scans for key packets.
then stores the name and ip address of each user connected to you.
as well as provides an http interface to kick/ban players.
works on xp32, vista 32 64 and win7 32 64
http://sof.adivinedude.com/downloads/index.php?dir=&file=COD_ADMIN_v2.4_source_code.zip

Identify user and machine on the local network

In my company we use small application called IPMsg, a messenger kind of tool to pass messages and file to other fellows in company, even it allows to multicast the message.
And also it lists the user name, host name and IP addresses of users.
How can it do that? There is no server present for message routing and when checked through netstat command in CMD it does not show any details like what protocol and port it is using to communicate.
There is source code also available on the same site which is in VC++. I didn't understand a line of code... (I'm a C# guy)
Can anyone explain me how it can do that?
One simple way would be to let the application listen on a certain network port, and when you start your instance of it, it tries to connect to that port on each computer on the same network. If that other computer has that port open, and answers correctly, then you have found another instance of the application.
IPMsg probably multicasts a request for all clients to report their user and host details.
A similar mechanism is used when Windows Explorer attempts to find other machines on a network. A good description of this type of multicasting discovery is described here.
IPMsg is a daemon which listens to incoming connections on a specific port which is the connection port. You can find out which port it used by using Wireshark.
Start wireshark, start listening on the interface where you have connected to LAN and then start sending any message, wireshark will show you the message on the screen with the port number also.
The application is a peer-to-peer software and doesn't require a central server software to route messages. it only has a small daemon which accepts incoming connections. This is the way Jabber Instant messaging protocol also works.
As you said it lists username, hostname and ip address of users, do you mean it pings the network and finds it? If yes, then it is actually possible to find the IP addresses of computers on the Local Network which requires you to know the subnet on which you are connected.
You can use ARP/ICMP Ping to know the hosts present on your network provided you enter the correct subnet information
Multicasting a message is also nothing special. It is a feature provided with all Networking Stacks.
If you want mutlicasting in .NET, it is allowed. Check this page on Code Project which gives a nice example

Categories

Resources