使用DatagramSocket

时间:2018-08-17 09:04:46

标签: java udp syslog

我试图让syslog服务器接收解析并通过Mikrotik路由器存储syslog消息。我已经使用DatagramSocket来接收udp日志消息。它接收日志消息,但是在消息中找不到priorityTime Stamp。我是否以错误的方式解析消息?我以前没有使用syslog的经验,所以请帮忙。

public class LogReceiver extends Thread {


public static void main(String [] args) {
    StartBroadcastReciever();
}

private static void StartBroadcastReciever(){
     new Thread() {
           public void run() {

            try {
                int port = 514;//getPort();
                DatagramSocket dsocket = new DatagramSocket(port);
                byte[] buffer = new byte[6048];

                DatagramPacket packet = new DatagramPacket(buffer,
                buffer.length);
                while (true) {
                    System.out.println("Receiving...");
                    dsocket.receive(packet);
                    String msg = new String(buffer, 0, packet.getLength());
                    String Address=packet.getAddress().toString();


                    System.out.println("The message = "+msg);


                    packet.setLength(buffer.length);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();
  }
}

控制台:

  

正在接收...消息=防火墙,信息转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK),   157.240.13.32:443->192.168.5.254:56390,NAT 157.240.13.32:443->(192.168.43.211:56390->192.168.5.254:56390),len 52正在接收...消息=防火墙,信息农村:转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK),   157.240.13.32:443->192.168.5.254:56390,NAT 157.240.13.32:443->(192.168.43.211:56390->192.168.5.254:56390),len 52正在接收...该消息=防火墙,信息转发:在:   out:wan_2,src-mac c0:4a:00:b4:7a:71,proto TCP(ACK,PSH),   192.168.4.254:34940->157.240.13.32:443、NAT(192.168.4.254:34940->192.168.43.211:34940)->157.240.13.32:443、len   323正在接收...消息=防火墙,信息农村:转发:   in:out:wan_2,src-mac c0:4a:00:b4:7a:71,proto TCP   (ACK,PSH),192.168.4.254:34940-> 157.240.13.32:443、NAT   (192.168.4.254:34940->192.168.43.211:34940)->157.240.13.32:443,len   323正在接收...消息=防火墙,信息转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK),   157.240.13.32:443->192.168.4.254:34940,NAT 157.240.13.32:443->(192.168.43.211:34940->192.168.4.254:34940),len 52正在接收...消息=防火墙,信息农村:转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK),   157.240.13.32:443->192.168.4.254:34940,NAT 157.240.13.32:443->(192.168.43.211:34940->192.168.4.254:34940),len 52正在接收...消息=防火墙,信息转发:在:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK,PSH),   157.240.13.19:443->192.168.5.254:46209,NAT 157.240.13.19:443->(192.168.43.211:46209->192.168.5.254:46209),len 91正在接收...该消息=防火墙,信息农村:转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK,PSH),   157.240.13.19:443->192.168.5.254:46209,NAT 157.240.13.19:443->(192.168.43.211:46209->192.168.5.254:46209),len 91正在接收...该消息=防火墙,信息转发:在:   out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP(ACK),   192.168.5.254:46209->157.240.13.19:443,NAT(192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 52   正在接收...消息=防火墙,信息农村:转发:   in:out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP   (ACK),192.168.5.254:46209-> 157.240.13.19:443,NAT   (192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 52   正在接收...消息=防火墙,信息转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK,FIN),   157.240.13.19:443->192.168.5.254:46209,NAT 157.240.13.19:443->(192.168.43.211:46209->192.168.5.254:46209),len 52正在接收...该消息=防火墙,信息农村:转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK,FIN),   157.240.13.19:443->192.168.5.254:46209,NAT 157.240.13.19:443->(192.168.43.211:46209->192.168.5.254:46209),len 52正在接收...该消息=防火墙,信息转发:在:   out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP(ACK,PSH),   192.168.5.254:46209->157.240.13.19:443,NAT(192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 91   正在接收...消息=防火墙,信息农村:转发:   in:out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP   (ACK,PSH),192.168.5.254:46209-> 157.240.13.19:443、NAT   (192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 91   正在接收...消息=防火墙,信息转发:在:   out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP(ACK,FIN),   192.168.5.254:46209->157.240.13.19:443,NAT(192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 52   正在接收...消息=防火墙,信息农村:转发:   in:out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP   (ACK,FIN),192.168.5.254:46209->157.240.13.19:443,NAT   (192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 52   正在接收...消息=防火墙,信息转发:在:   out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP(ACK),   192.168.5.254:46209->157.240.13.19:443,NAT(192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 52   正在接收...消息=防火墙,信息农村:转发:   in:out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP   (ACK),192.168.5.254:46209-> 157.240.13.19:443,NAT   (192.168.5.254:46209->192.168.43.211:46209)->157.240.13.19:443,len 52   正在接收...消息=防火墙,信息转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(RST),   157.240.13.19:443->192.168.5.254:46209,NAT 157.240.13.19:443->(192.168.43.211:46209->192.168.5.254:46209),len 40正在接收...该消息=防火墙,信息农村:转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(RST),   157.240.13.19:443->192.168.5.254:46209,NAT 157.240.13.19:443->(192.168.43.211:46209->192.168.5.254:46209),len 40正在接收...消息= pppoe,信息PPPoE连接已建立   从80:66:29:0A:82:29接收中...消息=防火墙,信息   前进:进:出:wan_2,src-mac 74:da:38:7c:09:19,   原始TCP(ACK,FIN),192.168.5.254:56390->157.240.13.32:443,NAT   (192.168.5.254:56390->192.168.43.211:56390)->157.240.13.32:443,len 52   正在接收...消息=防火墙,信息农村:转发:   in:out:wan_2,src-mac 74:da:38:7c:09:19,proto TCP   (ACK,FIN),192.168.5.254:56390->157.240.13.32:443,NAT   (192.168.5.254:56390->192.168.43.211:56390)->157.240.13.32:443,len 52   正在接收...消息=防火墙,信息转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK),   157.240.13.32:443->192.168.5.254:56390,NAT 157.240.13.32:443->(192.168.43.211:56390->192.168.5.254:56390),len 52正在接收...消息=防火墙,信息农村:转发:in:wan_2   出:,src-mac 02:08:22:64:ee:b5,原始TCP(ACK),   157.240.13.32:443->192.168.5.254:56390,NAT 157.240.13.32:443->(192.168.43.211:56390->192.168.5.254:56390),len 52正在接收...

0 个答案:

没有答案