返回顶部

Python以TCP、ICMP(nmap模块与scapy模块)扫描存活主机

题记

      Kali的scapy模块IP与ICMP接口有问题啊,老报错,不过脚本编写思路与前面类似。就是改改发包形式。能扫描外网主机了。

ICMP(scapy)

import sys

if len(sys.argv) != 2 :

    print ('usage:icmpPing <ip>\n eg:icmpPing 192.168.0.1')

    sys.exit(1)

from scapy.all import sr,IP,ICMP

ans,unans=sr(ip(sys.argv[1])/ICMP())

for snd,rcv in ans :

    print rcv.sprintf("%IP.src% is alive")

ICMP(nmap)

import sys

if len(sys.argv) != 2:

    print ('usage:icmpPing <ip>\n eg:icmpPing 192.168.0.1')

    sys.exit(1)

import nmap

nm=nmap.PortScanner()

nm.scan(sys.argv[1],arguments="-sn -PE")

for host in nm.all_hosts():

    print ("-----------------------------")

    print ('Host:%s(%s)'%(host,nm[host].hostname()))

    print ('State:%s'% nm[host].state())

TCP(scapy)

import sys

if len(sys.argv) != 3

    print ('usage:tcpPing <ip>\n eg:tcpPing 192.168.0.1 80')

    sys.exit(1)

from scapy.all import sr,TCP,IP

ans,unans=sr(ip(dst=sys.argv[1])/TCP(dport=int(sys.argv[2]),flags='s'))

for snd,rcv in ans :

    print rcv.sprintf("%IP.src% is alive")

TCP(nmap)

import sys

if len(sys.argv) != 2:

    print ('usage:tcpPing <ip>\n eg:tcpPing 192.168.0.1')

    sys.exit(1)

import nmap

nm=nmap.PortScanner()

nm.scan(sys.argv[1],arguments="-sT")

for host in nm.all_hosts():

    print ("-----------------------------------------")

    print ('Host:%s(%s)'%(host,nm[host].hostname()))

    print ('State:%s'% nm[host].state())

posted @ 2020-12-21 20:09  11阳光  阅读(1073)  评论(0编辑  收藏  举报