Python编写整理ipC段脚本

发布于 2020-08-16  191 次阅读


0x01 代码

#整理ip.txt 输出C段
#——peekeyes——
import sys

if len(sys.argv) == 2:
    text = sys.argv[1]
    print("提示:脚本已运行,结果输出到ipc.txt...")
    f = open(text,'r')
    for i in f:
        line = (i.rstrip('\n').split('.')[:-1])
        ipstart = ('.'.join(line)+'.'+str(1))
        ipend = ('.'.join(line)+'.'+str(255))
        result = open('ipc.txt', 'a+')
        with open('ipc.txt') as f:
            if ipstart not in f.read():
                result.write(f"{ipstart} {ipend}")
                result.write('\n')
                result.close()
else:
    print("Tips:python3 ipc.py <ip.txt>")
#列出ip.txt中的全部C段
#——peekeyes——
import sys

if len(sys.argv) == 2:
    text = sys.argv[1]
    print("提示:脚本已运行,结果输出到ipc.txt...")
    f = open(text,'r')
    for i in f:
        line = (i.rstrip('\n').split('.')[:-1])
        for a in range(1,255):
            ipc = ('.'.join(line)+'.'+str(a))
            result = open('ipc.txt', 'a+')
            with open('ipc.txt') as f:
                if ipc not in f.read():
                    result.write(ipc)
                    result.write('\n')
                    result.close()
else:
    print("Tips:python3 ipc_all.py <ip.txt>")
#列出ip.txt中的全部C/B段
import struct
import socket
import sys

def findIPs(start, end):
    ipstruct = struct.Struct('>I')
    start, = ipstruct.unpack(socket.inet_aton(start))
    end, = ipstruct.unpack(socket.inet_aton(end))
    return [socket.inet_ntoa(ipstruct.pack(i)) for i in range(start, end+1)]
if len(sys.argv) == 2:
    text = sys.argv[1]
    f = open(text,'r')
    for a in f:
        line = (a.rstrip('\n').split(' ')[:-1])
        line2 = (a.rstrip('\n').split(' ')[::-2])
        ipstart = ('.'.join(line))
        ipstart2 = ('.'.join(line2))
        aa = findIPs(ipstart,ipstart2)
        for i in aa:
            ipc = (i.rstrip('\n'))
            print(ipc)
            result = open('ipc.txt', 'a+')
            result.write(ipc)
            result.write('\n')
            result.close()
else:
    print("Tips:python3 ipbc.py <ip.txt>")

我不懂世界到底在热闹些什么