Python-Scan LAN available ports __python

Source: Internet
Author: User


do_scan_port.py

#!/usr/bin/env python
#-*-CODING:GBK-*-
#-*-coding:utf_8-*-

import socket from

do_valid_ip import *

# SCAN Specifies IP port

def test_port (dst,port):
    os.system (' title ' +str (port))

    Cli_sock = socket.socket (socket . af_inet, Socket. Sock_stream
    Try:
        indicator = CLI_SOCK.CONNECT_EX ((DST, Port)
        cli_sock.close ()
        If indicator = 0: Return is
            True
        else: return
            False
    except: Pass

ip_prefix = "172.18.228";
Find_port = 5555
print "Start scan valid port" + str (find_port)
for I in range (1, 256):
    IP = '%s.%s '% (IP _prefix, i)
    if Ping_ip (IP):
        Porton = Test_port (IP, 5555);
        If Porton:
            print IP + "got valid port"
print "End scan valid port" + str (find_port)


do_valid_ip.py

#-*-Coding:utf-8-*-# author:orangleliu date:2014-11-12 # python2.7.x ip_scaner.py ' "' Scan active IP execution in LAN: Python IP_SC aner.py 192.168.1.1 ' Import platform import sys import OS import time import thread Def get_os (): "' Get O S type ' OS = Platform.system () If OS = "Windows": Return "n" Else:return "C" def Ping _ip (ip_str): cmd = ["Ping", "-{op}". Format (Op=get_os ()), "1", ip_str] output = Os.popen ("". Join (CMD)). ReadLines () flag = False for line in list (output): If not line:continue if Str
        . Upper (). Find ("TTL") >= 0:flag = True break if Flag:return true else:
        Return False def find_ip (ip_prefix): "" gives the current 127.0.0, then scans the entire segment for all addresses ' for I-in range (1, 256): ip = '%s.%s '% (Ip_prefix, i) Thread.start_new_thread (ping_ip, (IP,)) Time.sleep (0.3) If __name__ = "__ main__ ": print" starT time%s "% time.ctime () Commandargs = sys.argv[1:] args =" ". Join (Commandargs) Ip_prefix = '. '. Join (Args.split ('. ')
    [:-1])
 FIND_IP (ip_prefix) print "End time%s"% Time.ctime ()


If Port 5555 is open, combine   ADB remote debugging/Network debugging   can control the phone.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.