get ip of user in csharp

To get the IP address of a user in C#, you can use the System.Net.Sockets.Socket class. Here is an example:

main.cs
using System.Net;
using System.Net.Sockets;

// create a new socket and connect to the server
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Connect("example.com", 80);

// get the local endpoint (i.e. the client's IP address and port number)
var localEndPoint = socket.LocalEndPoint as IPEndPoint;
Console.WriteLine("Client IP: {0}, Port: {1}", localEndPoint.Address, localEndPoint.Port);

// close the socket
socket.Close();
477 chars
14 lines

This code creates a new socket and connects to a server (in this case, example.com on port 80). It then gets the local endpoint of the socket, which contains the client's IP address and port number. The IP address is stored in the Address property of the IPEndPoint object, which can be used for further processing. Finally, the socket is closed.

gistlibby LogSnag