0 votes
by (210 points)

Hi,

I would like to know the IP address of the machine that sent a given syslog message (similar to recvfrom).
https://linux.die.net/man/2/recvfrom

How can this be done?

I can see there is a hostname field, but this value is optional and it is not necessarily the same thing.

Thanks in advance,

Toby

Applies to: Syslog

1 Answer

0 votes
by (148k points)

The MessageReceived event arguments provide the RemoteEndPoint property that can be used to retrieve the remove machine's IP address and port:

// create a server instance
var server = new SyslogServer();

// bind endpoints
server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Udp);
server.Bind(SyslogServer.DefaultPort, SyslogTransportProtocol.Tcp);

// register an event handler for received messages
server.MessageReceived += (s, e) =>
{
    Console.WriteLine("Message from {0}: {1}", e.RemoteEndPoint.Address, e.Message.Text);
};
by (210 points)
Sorry I missed that.  That's exactly what I was looking for.  Thanks for the fast response!
...