这个帖子是给分的,因为一次只能给100分呵呵,分两个帖子给分

解决方案 »

  1.   


    import java.io.InputStream;
    import java.io.FileInputStream;
    import java.io.IOException;import java.util.ArrayList;
    import java.util.List;public class LoggerReader {

    private String content = null;

    private List<String> ipList = new ArrayList<String>();

    private List<String> osList = new ArrayList<String>();

    private static final String INTERESTING_IP = "Interesting ports on ";

    private static final String NO_OS_MATCH = "No OS matches for host";

    private static final String OS_DETAIL = "OS details:";

    public void readByteByFileStream(String url) {
    try {
    readByteByStream(new FileInputStream(url));
    } catch(IOException e) {
    e.printStackTrace();
    }
    }

    public void readByteByStream(InputStream in) throws IOException {
    byte[] b = new byte[in.available()];
    in.read(b);
    content = new String(b);
    in.close();
    }

    public void toLogger() {
    for (int i = 0; i < ipList.size(); i++) {
    System.out.println("IP:" + ipList.get(i));
    System.out.println("OS:" + osList.get(i));
    }
    }

    public void parse() {
    for (int index = 0; index < content.length() && 
    content.indexOf(INTERESTING_IP, index) != -1; index++) {
    int ipStartIndex = content.indexOf(INTERESTING_IP, index);
    int ipEndIndex = content.indexOf(":", ipStartIndex + INTERESTING_IP.length());
    ipList.add(content.substring(ipStartIndex + INTERESTING_IP.length(), ipEndIndex));
    index = ipEndIndex;

    int ipNextStartIndex = content.indexOf(INTERESTING_IP, index);
    int osStartIndex = content.indexOf(OS_DETAIL, index);
    if (osStartIndex > ipNextStartIndex || osStartIndex == -1) {
    osList.add(NO_OS_MATCH);
    } else {
    int osEndIndex = content.indexOf(":", osStartIndex + OS_DETAIL.length());
    osList.add(content.substring(osStartIndex + OS_DETAIL.length() + 1, osEndIndex));
    }
    }
    }
    public static void main(String[] args) {

    LoggerReader reader = new LoggerReader();
    reader.readByteByFileStream("e:\\a.txt");
    reader.parse();
    reader.toLogger();
    }
    }
    a.txt
    # Nmap 4.53 scan initiated Thu Nov 06 10:16:56 2008 as: nmap -sS -O -v -oN baohui 192.168.6.20-23
    Initiating OS detection (try #1) against 3 hosts
    Retrying OS detection (try #2) against 2 hosts
    Interesting ports on 192.168.6.21:
    Not shown: 1709 filtered ports
    PORT    STATE SERVICE
    80/tcp  open  http
    139/tcp  open  netbios-ssn
    443/tcp  open  https
    445/tcp  open  microsoft-ds
    3389/tcp open  ms-term-serv
    MAC Address: 00:1B:B9:85:FE:95 (Elitegroup Computer System Co.)
    Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
    Device type: general purpose
    Running: Microsoft Windows XP
    OS details: Microsoft Windows XP SP2
    Network Distance: 1 hop
    TCP Sequence Prediction: Difficulty=263 (Good luck!)
    IP ID Sequence Generation: IncrementalInteresting ports on 192.168.6.22:
    Not shown: 1709 closed ports
    PORT    STATE SERVICE
    135/tcp  open  msrpc
    139/tcp  open  netbios-ssn
    445/tcp  open  microsoft-ds
    990/tcp  open  ftps
    1025/tcp open  NFS-or-IIS
    MAC Address: 00:1A:A0:3A:76:AC (Dell)
    No OS matches for host
    Network Distance: 1 hopInteresting ports on 192.168.6.23:
    Not shown: 1704 closed ports
    PORT    STATE SERVICE
    21/tcp  open  ftp
    80/tcp  open  http
    135/tcp  open  msrpc
    139/tcp  open  netbios-ssn
    443/tcp  open  https
    445/tcp  open  microsoft-ds
    912/tcp  open  unknown
    990/tcp  open  ftps
    1025/tcp open  NFS-or-IIS
    1026/tcp open  LSA-or-nterm
    MAC Address: 00:1E:68:5C:19:E6 (Quanta Computer)
    No OS matches for host
    Network Distance: 1 hopRead data files from: E:\nmap-4.53
    OS detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .
    # Nmap done at Thu Nov 06 10:17:13 2008 -- 4 IP addresses (3 hosts up) scanned in 16.938 seconds 
    这是刚才给一位朋友作的提取logger的方法
    思路是首先得到流,然后组成String,最后用StringApi完成功能