python如何写app服务器端口_python3写的一个检测远程服务器端口脚本

1、脚本

#!/usr/bin/env python

import os

import sys

import socket

import msvcrt

b = sys.platform

arr=[]

if ‘win*‘ == b:

config = sys.path[0] + ‘\config.txt‘

else:

config = sys.path[0] + ‘/config.txt‘

file = open(config,"r")

for line in file.readlines():

if line.startswith("#"):

continue

else:

arr.append((line.replace(‘\n‘,‘‘).split(‘ ‘)))

file.close()

for arra in arr:

sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sk.settimeout(1)

ip = (str(arra[0]),int(arra[1]))

try:

sk.connect(ip)

print(arra[0] + ‘的端口‘ + arra[1] + ‘通‘)

except Exception :

print(arra[0] + ‘的端口‘ + arra[1] + ‘不通‘ )

sk.close()

msvcrt.getch()

2 配置文件:

#在下方输入服务器的IP或者域名,然后输入空格在加一个端口

#例如:www.xxx.com 80 10.110.110.110 100

www.baidu.com 443

10.11.21.51 110

10.11.29.32 54

10.11.21.51 80

120.2.1.3 569

原文:http://blog.51cto.com/xiaoyuanzheng/2162348

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值