#!/usr/bin/env python
# encoding: utf-8
import socket,sys
ip = '172.16.138.238'
port = [23,80,8080,123,465,789,323,3306,3389,139,138]
def portScan(ip,port):
s = socket.socket()
s.settimeout(1)
try:
s.connect((ip,port))
s.close()
return True
except:
return False
def scan(ip,port):
for x in port:
r = portScan(ip,x)
if r:
sys.stderr.write('%s:%s is open\n' % (ip,x))
else:
print ('%s:%s is close' % (ip,x))
scan(ip,port)