定義函數(shù)
二級標(biāo)題
- 事情1
- 事情2
- 事情3
代碼
#coding:utf-8
# 引入os模塊
importos
# 引入時間模塊
importtime
importsys
# importlib.reload(sys)
# print (sys.getdefaultencoding( ))
# sys.setdefaultencoding( "utf-8" )
hosts=["192.168.31.1","www.163.com","www.baidu.com","www.taobao.com"]
defpingWebsite(websites):
forwebsiteinwebsites:
start=time.time()
response=os.system("ping -c 1 "+website)
duration=time.time()-start
print("我們正在ping:", website,"耗時:",ms(duration),'\n')
# def printChn(msg):
# return msg.encode(sys.getdefaultencoding(), 'replace')
#中文亂碼轉(zhuǎn)譯
# def printChn(str):
# chn = str
# #.encode('utf-8').decode('gbk','ignore')
# return chn
defms(a):
returnstr(round(a*1000,1))+" 毫秒"
print('\n')
pingWebsite(hosts)