批量测试端口开放

…..

PowerShell简单测试端口开放

import-Module .\Invoke-TestPort
Invoke-TestPort -ipLists C:\x.txt 23

function Invoke-TestPort
{
    [CmdletBinding()] Param (
        [Parameter(Mandatory = $true, Position = 0)]
        [Alias("Url","Domain")]
        [String]
        $ipLists,

        [Parameter(Mandatory = $true ,Position = 1)]
        [String]
        $Port
    )
    Process{
       Write-Host "Starting TestPort ..."
       $ips = Get-Content -ErrorAction SilentlyContinue -Path $ipLists
       foreach ($ip in $ips){
           try{
               $socket = new-object System.Net.Sockets.TcpClient($ip, $Port)

           }
           catch [Exception]{
               Write-Host $ip":"$Port "CAN'T Connected"
               continue
           }
           Write-Host $ip":"$Port "CAN Connected"
        }
    }
}

Python批量测试Telnet端口开放

import sys
import getpass
import pexpect
import telnetlib
import threadpool

OKWHITE = '\033[1;37m'
OKENDC = '\033[0m'

class Telnets_OK():
    def __init__(self,ip,thread_id,Store_Result_txt):
        self.ip                      = ip
        self.thread_id               = thread_id
        self.Store_Result_txt        = Store_Result_txt

        self.OKWHITE = '\033[1;37m' 
        self.OKGREEN = '\033[92m'
        self.OKWARNING = '\033[93m' 
        self.OKFAIL = '\033[91m'    
        self.OKENDC = '\033[0m'
        self.login()

    def Store_ok_txt(self):
        with open('Can_Telnet_{0}'.format(self.Store_Result_txt),'a+') as f:
            f.write(self.ip + "^")
            f.write("\n")

    def Store_not_ok_txt(self):
        with open('Cannot_Telnet_{0}'.format(self.Store_Result_txt),'a+') as f:
            f.write(self.ip + "^")
            f.write("\n")

    def login( self ):
        cmd = 'telnet ' + self.ip 
        child = pexpect.spawn(cmd)
        index = child.expect(["[lL]ogin", "(?i)Unknown host", pexpect.EOF, pexpect.TIMEOUT])
        if ( index == 0 ):
            print self.OKGREEN +   "[+] can   telnet : {0}".format(self.ip) + self.OKENDC
            self.Store_ok_txt()
        else:  
            print self.OKFAIL + "[-] can\'t telnet : {0}".format(self.ip) + self.OKENDC

            self.Store_not_ok_txt()
        child.close()  

def Load_Urls_Txt( txt):
    Urls_Pass   = []
    f           = open( txt, 'r')
    line        = f.readline().strip('\n')
    while (line):
        Urls_Pass.append(line)
        line    = f.readline().strip('\n')
    f.close()
    return Urls_Pass

def main(Urls_Pass ,Store_Result_txt):
    task_pool = threadpool.ThreadPool(20)
    templists = []
    for i in range(0,len(Urls_Pass)):
        a       = Urls_Pass[0]
        temp    = a.split('^')
        udic    = {}
        udic['ip']      = temp[0] 
        udic['Store_Result_txt']= Store_Result_txt
        udic['thread_id']   = i
        tmp = (None,udic)
        Urls_Pass.remove(a)
        templists.append(tmp)
    request_list = threadpool.makeRequests(Telnets_OK , templists)
    map(task_pool.putRequest , request_list)
    task_pool.wait()

if __name__ == '__main__':
    if len(sys.argv) != 2:
        print OKWHITE
        print 'Usage      : python {0} <txt>'.format(sys.argv[0]) 
        print 'txt        : domain or ip'
        print 'Threads    : 20 (default)'
        print 'Name       : piliang telnet'
        print OKENDC
        sys.exit(1)
    print OKWHITE + "Loading : {0}".format(sys.argv[1]) 
    txt             = ''.join(sys.argv[1])
    Urls_Pass    = Load_Urls_Txt(txt)
    print "Lines : {0}".format(len(Urls_Pass)) + OKENDC
    main(Urls_Pass, sys.argv[1])