找出文件arp0.txt中所有找出文件arp0.txt中所有
1 时间; 
2 ip1;
3 ip2;
4 mac;
并导进另外一个文件中  arp1.txt22:51:46.132995 00:0c:f7:fb:02:18 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has 219.231.1.78 tell 219.231.1.254 
22:51:46.133011 00:0c:f7:fb:02:18 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has 219.231.1.23 tell 219.231.1.254 
22:51:50.132982 00:0c:f7:fb:02:18 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has 219.231.1.78 tell 219.231.1.254 
22:51:51.167636 00:1b:b9:d9:a6:98 (oui Unknown) > 00:0c:f7:fb:02:1c (oui Unknown), ethertype ARP (0x0806), length 42: arp who-has 10.2.105.254 tell 10.2.105.25 
22:51:51.167902 00:0c:f7:fb:02:1c (oui Unknown) > 00:1b:b9:d9:a6:98 (oui Unknown), ethertype ARP (0x0806), length 60: arp reply 10.2.105.254 is-at 00:0c:f7:fb:02:1c (oui Unknown) 
22:51:54.133034 00:0c:f7:fb:02:18 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has 219.231.1.78 tell 219.231.1.254 
22:51:58.184903 00:0c:f7:fb:02:18 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has 219.231.1.23 tell 219.231.1.254 
22:52:00.931421 00:1b:b9:a1:fb:9b (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 106: arp who-has 10.2.105.4 tell 10.2.105.100 

解决方案 »

  1.   

    上回回过一次
    String s = "22:51:46.132995 00:0c:f7:fb:02:18 (oui Unknown) > Broadcast, ethertype ARP (0x0806), length 60: arp who-has* 219.231.1.78 tell 219.231.1.254";
            Pattern p = Pattern
                .compile("(\\d{2}:\\d{2}:\\d{2}.\\d{6})(?:.*?)(\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3})\\s+tell\\s+(\\d{1,3}.\\d{1,3}.\\d{1,3}.\\d{1,3})\\s*");
            Matcher m = p.matcher(s);
            while (m.find()) {
                System.out.println(m.group(1));
                System.out.println(m.group(2));
                System.out.println(m.group(3));
            }