0 votes
by (210 points)


I would like to know the IP address of the machine that sent a given syslog message (similar to 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,


Applies to: Syslog

1 Answer

0 votes
by (144k 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!