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())


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM