Remote IP Address Information

I want to keep track of all the IP addresses that my computer interacts with. I am using C # and Visual Studio. There is one listBox in which I will host the entire remote IP address. I am new to network programming, so I need some direction in this problem.

My question is: how to do this? How to get information about the remote IP addresses that my computer connects to?

+3
source share
4 answers

Most socket programming applications use the TCP socket APIs, which are roughly standardized between operating systems. If you just want to write a simple server and visualize clients talking on your server working in your process, which is pretty easy. However, your process cannot see socket connections talking to other processes on your computer with a typical socket API.

IP-, , API . . Windows API Winsock, , , tcp/ip . , TCP IP-. ? TCP , IP. ARP, UDP, TCP, ICMP .

, , , , . . , . , , ? .

: - WinPcap #. . .

+2

netstat, , IP- . .

, , :

C:\Users\chibacity>netstat -a -n

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    10.0.0.107:32495       209.85.229.125:5222    ESTABLISHED
  TCP    10.0.0.107:32507       209.85.229.125:5222    ESTABLISHED
  TCP    10.0.0.107:32520       209.85.229.18:443      ESTABLISHED
  TCP    10.0.0.107:32755       209.85.227.109:993     ESTABLISHED
  //etc...

, , :

PS C:\Windows\system32> netstat -a -n -b

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    10.0.0.107:32495       209.85.229.125:5222    ESTABLISHED
 [googletalk.exe]
  TCP    10.0.0.107:32507       209.85.229.125:5222    ESTABLISHED
 [chrome.exe]
  TCP    10.0.0.107:32520       209.85.229.18:443      ESTABLISHED
 [chrome.exe]
  TCP    10.0.0.107:32755       209.85.227.109:993     ESTABLISHED
  //etc...

.Net, System.Diagnostics.Process , :

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx

+3

Windows IP, iphlpapi, . , GetTcpTable GetUdpTable.

, C API. #, API P/Invoke. , . C #, System.Runtime.InteropServices . , , .

C, , [DllImport("iphlpapi.dll")] . PInvoke msdn , , pinvoke wiki. , , , - Pinvoke

+2

, ObservableCollection<string> mAccessInfo - , , , :

Socket socketForClient = tcpListener.AcceptSocket( );

if (socketForClient.Connected)
{
    mAccessInfo.Add(socketForClient.RemoteEndPoint.ToString());
    //do other stuff...
}

ObservableCollection, , , , , .

Change . As Cody Gray pointed out, this will not work if you have an IP address between the proxy / router / NAT, etc.

+1
source

Source: https://habr.com/ru/post/1787149/


All Articles