#coding:utf-8

import os
import re

content = """Please input your content here!!!
example:
[+] 10.150.50.88:445      - C$ - (DS) Default share
[+] 10.150.50.88:445      - D$ - (DS) Default share
[+] 10.150.50.88:445      - IPC$ - (I) Remote IPC
10.150.50.11 asdfasd 150.50.60.6
Reply from 192.168.0.2: bytes=32 time<1ms TTL=128
Reply from 192.168.22.9: bytes=32 time<1ms TTL=128

Result is:
10.150.50.88
10.150.50.11
150.50.60.6
192.168.22.9
192.168.0.2

"""
with open("content.txt",'w') as content_:
    content_.write(content)

os.system("content.txt")
ips_str = [] #store ips


f = open("content.txt")
ips = f.readlines()
f.close()
for ip in ips:
    IP_str = ip.strip()
    try:
        ip = re.findall( r'[0-9]+(?:\.[0-9]+){3}', IP_str )
        for ii in ip:
            ips_str.append(ii)
        #print ips_str
    except Exception,e:
        pass

ips_str_unique = list(set(ips_str))
os.system("del content.txt")
for i in ips_str_unique:
    print i
    with open("content.txt",'a') as ipi:
        ipi.write(i+"\n")
os.system("content.txt")

发表评论

电子邮件地址不会被公开。 必填项已用*标注