尝遍人间多少味道,看过峡谷多少沙雕!

引言

前段时间在做信安之路成长挑战的Python开发,只做了第一关,刚看了看第二关,面向百度进行编程,实现了简单的主机存活扫描,就是有点慢,应该多加载一些多进程。
还有就是看python开发做了一个端口扫描的功能,但是也没有实现很强的功能,慢慢努力吧。

主机存活扫描

#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Author:@m0re
# Blog:https://m0re.top
# Date:2021/06/04
import time
import os
import threading

def ping_ip(ip_str):
    cmd = ["ping", "-n 1", "-v 1", ip_str]
    resopnse = os.popen(" ".join(cmd)).readlines()

    flag = False
    for line in list(resopnse):
        if not line:
            continue
        if str(line).upper().find("TTL") >= 0:
            flag = True
            break

    if flag:
        print(ip_str+' is alive')
    else:
        pass

print("example:127.0.0.")
ip_list = input("请输入您需要测试的IP段:")
for i in range(1,256):
    ip = (ip_list+str(i))
    scan = threading.Thread(target=ping_ip,args=(ip,))
    scan.start()
    time.sleep(0.3)

端口扫描

#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
# @Time    : 2021/5/30
# @Author  : m0re
# @Blog    : https://m0re.top/
"""
首先定义一个端口扫描函数
"""
import socket
from threading import Thread
import time

def zhuangbi():
    zhuangbi = """
                    ______                                                              
                   /      \                                                             
     _____  ____  /$$$$$$  |  ______    ______    _______   _______   ______   _______  
    /     \/    \ $$$  \$$ | /      \  /      \  /       | /       | /      \ /       \ 
    $$$$$$ $$$$  |$$$$  $$ |/$$$$$$  |/$$$$$$  |/$$$$$$$/ /$$$$$$$/  $$$$$$  |$$$$$$$  |
    $$ | $$ | $$ |$$ $$ $$ |$$ |  $$/ $$    $$ |$$      \ $$ |       /    $$ |$$ |  $$ |
    $$ | $$ | $$ |$$ \$$$$ |$$ |      $$$$$$$$/  $$$$$$  |$$ \_____ /$$$$$$$ |$$ |  $$ |
    $$ | $$ | $$ |$$   $$$/ $$ |      $$       |/     $$/ $$       |$$    $$ |$$ |  $$ |
    $$/  $$/  $$/  $$$$$$/  $$/        $$$$$$$/ $$$$$$$/   $$$$$$$/  $$$$$$$/ $$/   $$/ 

        """
    print(zhuangbi)

def main(target):
    print("开始扫描:%s"% target)
    for port in range(1,1024):
        conn = Thread(target=portscan,args=(target,port))
        conn.start()

def portscan(target, port):
    try:
        Client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
        Client.connect((target, port))
        print("[+] %s:%d 开放"% (target,port))
        Client.close()
    except:
        pass

if __name__ == '__main__':
    zhuangbi()
    target = input("请输入IP地址:")
    start = time.time()
    main(target)
    end = time.time()
    print("总耗时:%.2f s" % (end-start))

这个虽然low,但是有个装X代码。觉得挺好玩的!