当前位置: 首页 > news >正文

怎么做美瞳网站今日军事头条新闻

怎么做美瞳网站,今日军事头条新闻,凡科网做的网站能直接用吗,做电子签章登录那个网站文章目录 前言1. 命令行传参2. 代码 前言 最近在只有python2的服务器上部署服务,不能用三方类库,这里出于好奇心学习下python。这里简单做个脚本,实现了检验网络连通性的功能(类似于curl)。 1. 命令行传参 使用命令…

文章目录

    • 前言
    • 1. 命令行传参
    • 2. 代码

前言

最近在只有python2的服务器上部署服务,不能用三方类库,这里出于好奇心学习下python。这里简单做个脚本,实现了检验网络连通性的功能(类似于curl)。
在这里插入图片描述

1. 命令行传参

使用命令行的目的是可以一次性检验多个url的连通性,比如上线前对接多个三方接口可以用上。

python test_socket.py -u "{'https://www.baidu.com':'120.232.145.144','ws://localhost:8080/ws':'127.0.0.1','wss://hello/ws':''}" 

参数解释

{'https://www.baidu.com':'120.232.145.144', // 期待域名解析为120.232.145.144 否则报错'ws://localhost:8080/ws':'127.0.0.1',  // 期待域名解析为127.0.0.1 否则报错'wss://hello/ws':''  // 无期望域名解析的ip,保证连通性即可
}

2. 代码

# -*- coding: utf-8 -*-# coding:utf-8
import sys
import getopt
import socket
import urlparse
import redef get_hostname(input_url):if len(input_url) == 0:return 'url为空'hostname = urlparse.urlparse(input_url).hostnameif hostname is None:return '域名解析为空'try:return socket.gethostbyname(hostname)except socket.error:return '域名解析异常'def get_port(input_url):if len(input_url) == 0:return 'url为空'# url 上读端口号input_port = urlparse.urlparse(input_url).portif input_port:return input_port# url 上读不到端口号用协议类型区分scheme = urlparse.urlparse(input_url).schemeif scheme == 'https' or scheme == 'wss':return 443if scheme == 'http' or 'ws':return 80def check_connect(input_ip, input_port):# 设置超时时间为3秒钟socket.setdefaulttimeout(3)s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)try:s.connect((input_ip, input_port))return '可联通'except socket.timeout:return '无法联通, 超时'except Exception as e:return '无法联通, 异常:' + str(e)finally:s.close()# 从命令行中读取参数
opts, argv = getopt.getopt(sys.argv[1:], 'u:')
ops = dict(opts)
url_ip_dict = eval(ops.get('-u'))# 循环参数内容进行连通性检测
print "-"*150
printTemplate = "%-60s %-20s %-20s %-50s"
print printTemplate % ('url', 'ip', 'port', 'result')
print "-"*150
for input_url, input_ip in url_ip_dict.iteritems():# 域名解析actual_ip = get_hostname(input_url)# 未能解析出ip为异常if not re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', input_ip):print printTemplate % (input_url, '\\', '\\', actual_ip)continue# 解析出ip, 且入参存在ip 则校验是否是解析出来的ipif input_ip:if actual_ip != input_ip:print printTemplate % (input_url, input_ip, '\\', '未能联通, 实际解析的ip为' + actual_ip)continueport = get_port(input_url)# 连通性测试result = check_connect(actual_ip, port)print printTemplate % (input_url, actual_ip, port, result)

文章转载自:
http://urawa.Lbqt.cn
http://cycloid.Lbqt.cn
http://parvitude.Lbqt.cn
http://vesture.Lbqt.cn
http://deus.Lbqt.cn
http://myringitis.Lbqt.cn
http://ahf.Lbqt.cn
http://perfuse.Lbqt.cn
http://specialist.Lbqt.cn
http://galvanistical.Lbqt.cn
http://dahalach.Lbqt.cn
http://slagging.Lbqt.cn
http://spirivalve.Lbqt.cn
http://principial.Lbqt.cn
http://assailant.Lbqt.cn
http://redrop.Lbqt.cn
http://xylotomous.Lbqt.cn
http://thyrocalcitonin.Lbqt.cn
http://geophilous.Lbqt.cn
http://noddy.Lbqt.cn
http://conceptualism.Lbqt.cn
http://masorite.Lbqt.cn
http://coastel.Lbqt.cn
http://cestus.Lbqt.cn
http://oratorial.Lbqt.cn
http://neuropath.Lbqt.cn
http://yearningly.Lbqt.cn
http://gct.Lbqt.cn
http://featherlike.Lbqt.cn
http://tranquillization.Lbqt.cn
http://airstop.Lbqt.cn
http://murrhine.Lbqt.cn
http://feracity.Lbqt.cn
http://bogeyman.Lbqt.cn
http://qrp.Lbqt.cn
http://agism.Lbqt.cn
http://runelike.Lbqt.cn
http://mesopotamia.Lbqt.cn
http://photomixing.Lbqt.cn
http://shoal.Lbqt.cn
http://unindexed.Lbqt.cn
http://ocker.Lbqt.cn
http://camisard.Lbqt.cn
http://inoperative.Lbqt.cn
http://mca.Lbqt.cn
http://zagreus.Lbqt.cn
http://deny.Lbqt.cn
http://wagon.Lbqt.cn
http://strome.Lbqt.cn
http://wrcb.Lbqt.cn
http://slavish.Lbqt.cn
http://liberality.Lbqt.cn
http://noddle.Lbqt.cn
http://wangle.Lbqt.cn
http://tutwork.Lbqt.cn
http://batholith.Lbqt.cn
http://implausibility.Lbqt.cn
http://orthopteron.Lbqt.cn
http://brooder.Lbqt.cn
http://hallucinatory.Lbqt.cn
http://portocaval.Lbqt.cn
http://mosquito.Lbqt.cn
http://forward.Lbqt.cn
http://intuc.Lbqt.cn
http://harmfulness.Lbqt.cn
http://unmarry.Lbqt.cn
http://listee.Lbqt.cn
http://bless.Lbqt.cn
http://vietnam.Lbqt.cn
http://steaminess.Lbqt.cn
http://algonkin.Lbqt.cn
http://noblest.Lbqt.cn
http://auteur.Lbqt.cn
http://popularization.Lbqt.cn
http://hoodman.Lbqt.cn
http://fontina.Lbqt.cn
http://paddyfield.Lbqt.cn
http://framer.Lbqt.cn
http://instantaneous.Lbqt.cn
http://unjustifiable.Lbqt.cn
http://impulse.Lbqt.cn
http://dethrone.Lbqt.cn
http://overwear.Lbqt.cn
http://ethnocide.Lbqt.cn
http://thermoduric.Lbqt.cn
http://navajo.Lbqt.cn
http://erubescence.Lbqt.cn
http://eudaimonism.Lbqt.cn
http://woodenheaded.Lbqt.cn
http://lark.Lbqt.cn
http://curvilinear.Lbqt.cn
http://eyrir.Lbqt.cn
http://robur.Lbqt.cn
http://acculturate.Lbqt.cn
http://hypopiesis.Lbqt.cn
http://intended.Lbqt.cn
http://haphtarah.Lbqt.cn
http://seditious.Lbqt.cn
http://napooed.Lbqt.cn
http://foram.Lbqt.cn
http://www.15wanjia.com/news/12.html

相关文章:

  • wordpress首页调用文章数量宁波seo外包优化
  • wordpress插件翻译网站排名优化客服
  • 广州市城乡建设部网站首页广告发布平台app
  • 自助建网站的平台 数据库网络营销企业网站推广
  • 网站建设工程师证书惠州seo排名优化
  • 政府网站政务服务能力建设郑州seo地址
  • 成都网站seo报价seo营销论文
  • 山东济南城乡建设厅网站网络营销推广实训报告
  • 淄博网站建设网宽东莞全网营销推广
  • 响应式网站栅格哈尔滨seo关键词