现有一个文本文档,我对其中的一些数据比较感兴趣,想提取出来
提取出的格式大概是这个样子的:
IP:xxxxxxxx
OS:xxxxxxxx
PORT:xx,xx,xx,xxIP:xxxxxxxx
OS:xxxxxxxx
PORT:xx,xx,xx,xxIP:xxxxxxxx
OS:xxxxxxxx
PORT:xx,xx,xx,xx说明:OS是操作系统类型,它的值可能会有点不一样。PORT是计算机开放的端口
本人菜鸟,希望高手能给出代码,谢谢了!文本文档内容如下:我把要提取的内容用红色标示了出来# Nmap 4.53 scan initiated Thu Nov 13 13:07:09 2008 as: nmap -sS -O -oN scanresult 192.168.6.20-23 
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|authentication server
Running (JUST GUESSING) : Microsoft Windows XP|2003|2000 (96%), Juniper Windows 2000 (87%)
Aggressive OS guesses: Microsoft Windows XP SP2 (96%), Microsoft Windows Server 2003 SP2 (92%), Microsoft Windows XP SP 2 (91%), Microsoft Windows 2000 SP4 or Windows XP SP2 (91%), Microsoft Windows Server 2003 SP0 or Windows XP SP2 (90%), Microsoft Windows XP Professional SP2 (90%), Microsoft Windows 2003 Small Business Server (89%), Microsoft Windows Server 2003 SP1 or SP2 (89%), Microsoft Windows XP Professional SP2 (firewall enabled) (88%), Microsoft Windows XP Professional SP2 (Russian) (88%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 1 hopInteresting ports on 192.168.6.22:
Not shown: 1706 closed ports
PORT     STATE SERVICE
80/tcp   open  http
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
990/tcp  open  ftps
999/tcp  open  garcon
1025/tcp open  NFS-or-IIS
6001/tcp open  X11:1
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)
OS details: Microsoft Windows XP SP2
Network Distance: 1 hopOS detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .
# Nmap done at Thu Nov 13 13:07:32 2008 -- 4 IP addresses (3 hosts up) scanned in 24.125 seconds

解决方案 »

  1.   

                           
      代码就不写了,说个思路,但不定能够全部获得:
      读取每一行,如果以
      Interesting ports on 
      开头,就把接下来的部分放到  ip中
      
      如果以 PORT 开头,就读取接下来的行,并在接下来的行中读 /之前的部分
      放入 port
      
      如果以 Mac 开头的,读取接下来的行,放入 OS,但这个似乎有点问题,与第一个不符
      
      

  2.   

    package com.suypower.chengyu.io;import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    import java.io.InputStream;
    import java.io.InputStreamReader;public class csdnFileString {
    public static void main(String[] args) throws Exception
    {
    //存放你的文件路径
    String url = "d:\\csdn\\test.txt";
    File file = new File(url);
    if(!file.exists())
    {
    System.out.println("文件不存在,请检查你的url路径");
    }
    else
    {
    // 读取你的文本
    System.out.println("文件当期路径:"+file.getAbsolutePath());
    InputStream is = new FileInputStream(file);
    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);
    String line = "";
    String str = "";
    while((line = br.readLine()) != null)
    {
    str += line;
    }
    System.out.println("你的文本文件:"+str);
    // 取出一组信息
    String[] information = str.split("hop");
    // 这里划分了4组信息,最后一个是没有用的,我们取前3个循环值
    for (int i = 0; i < 3; i++) 
    {
    String string = information[i];
    // 取出各个组中属性值
    int on = string .indexOf("on")+3;
    int not = string.indexOf("Not");
    String ip = string.substring(on,not);
    System.out.println("ip:"+ip);
    }
    }
    }}
      

  3.   

    以上是解析IP地址的,你参考一下,解析其他的也是一样,想想就可以了,不能把代码全贴出来了,要么楼主就不用动一下脑子就copy了,呵呵,不好意思哦
      

  4.   

    代码就不写了,说个思路,但不定能够全部获得: 
      读取每一行,如果以 
      Interesting ports on 
      开头,就把接下来的部分放到  ip中 
      
      如果以 PORT 开头,就读取接下来的行,并在接下来的行中读 /之前的部分 
      放入 port 
      
      如果以 Mac 开头的,读取接下来的行,放入 OS,但这个似乎有点问题,与第一个不符