+ -
当前位置:首页 → 问答吧 → [正则表达式]如果提取这样IP或Hostname?

[正则表达式]如果提取这样IP或Hostname?

时间:2011-07-01

来源:互联网

只要提取open     http这样标志IP或Hostname
如:"test.com.cn (192.168.0.1) 192.168.0.4"

以下是提取格式:
Nmap scan report for test.com.cn (192.168.0.1)
Host is up (0.18s latency).
Not shown: 985 closed ports
PORT     STATE    SERVICE      VERSION
21/tcp   open     tcpwrapped
22/tcp   open     ssh          OpenSSH 3.4p1 (protocol 1.99)
25/tcp   open     tcpwrapped
80/tcp   open     http         Apache httpd 2.0.55 ((Unix) mod_ssl/2.0.55 OpenSSL/0.9.8a mod_jk/1.2.15)
110/tcp  open     tcpwrapped
111/tcp  open     rpcbind
135/tcp  filtered msrpc
139/tcp  filtered netbios-ssn
143/tcp  open     tcpwrapped
443/tcp  open     ssl/http     Apache httpd 2.0.55 ((Unix) mod_ssl/2.0.55 OpenSSL/0.9.8a mod_jk/1.2.15)
445/tcp  filtered microsoft-ds
587/tcp  open     smtp         Sendmail 8.13.8/8.13.8
3306/tcp open     mysql        MySQL (unauthorized)
8009/tcp open     ajp13?
8080/tcp open     http         Apache Tomcat/Coyote JSP engine 1.1

Nmap scan report for 192.168.0.4
Host is up (0.17s latency).
Not shown: 994 filtered ports
PORT      STATE  SERVICE    VERSION
21/tcp    open   ftp        WU-FTPD wu-2.6.2-8
22/tcp    open   tcpwrapped
53/tcp    open   domain     ISC BIND 188web NS2
80/tcp    open   http       Apache httpd 2.0.40 ((Red Hat Linux))
113/tcp   closed auth
10000/tcp open   http       MiniServ 0.01 (Webmin httpd)


以下是不提取格式:
Nmap scan report for 192.168.0.2
Host is up (0.18s latency).
Not shown: 998 filtered ports
PORT     STATE SERVICE  VERSION
443/tcp  open  ssl/http Fnord httpd 1.8a
1723/tcp open  pptp     linux (Firmware: 1)

Nmap scan report for 192.168.0.3
Host is up (0.17s latency).
Not shown: 991 filtered ports
PORT      STATE  SERVICE    VERSION
20/tcp    closed ftp-data
21/tcp    open   ftp        vsftpd 2.0.7
22/tcp    open   tcpwrapped
25/tcp    open   smtp       Postfix smtpd
53/tcp    closed domain
80/tcp    closed http
113/tcp   closed auth
143/tcp   closed imap

作者: peterdocter   发布时间: 2011-07-01

本帖最后由 rdcwayx 于 2011-07-01 14:09 编辑
  1. awk 'BEGIN{RS="";FS="\n"}/open[ \t]*http/{print $0 FS}'  infile
复制代码

作者: rdcwayx   发布时间: 2011-07-01