在python的監(jiān)控apache服務(wù)實(shí)例
端口掃描代碼如下:
import socket
def main():
sk = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sk.settimeout(1000)
ip=raw_input('請(qǐng)輸入要掃描的服務(wù)器ip(default:\033[1;34;45m127.0.0.1\033[0m):')
if ip=='':
ip='127.0.0.1'
s=raw_input('請(qǐng)輸入開始端口(default:\033[1;34;45m80\033[0m)')
if s=='':
startport=80
else:
startport=int(s)
s=raw_input('請(qǐng)輸入結(jié)束端口(default:\033[1;34;45m80\033[0m)')
if s=='':
endport=80
else:
endport=int(s)
for port in range(startport,endport+1):
print('掃描端口:\033[1;34;45m%d\033[0m...................' % port)
try:
sk.connect((ip,port))
print('服務(wù)器 \033[1;34;45m%s\033[0m 端口 \033[1;34;45m%d\033[0m OK!' % (ip,port))
except Exception:
print('服務(wù)器 \033[1;34;45m%s\033[0m 端口 \033[1;34;45m%d\033[0m is not connected!' % (ip,port))
sk.close()
if __name__ == '__main__':
main()
點(diǎn)擊加載更多評(píng)論>>