cs

来源:互联网 发布:药店数据分析 编辑:程序博客网 时间:2024/04/29 00:30
import subprocess
def _pingtest(ip):
     #print('ping test: ping -n 2 %s'%ip)
     o = subprocess.getoutput('ping -n %s'%ip)
     if o.find('time='):
          print('[ + ] ALIVE')
          return True
     else:
          print('[ + ] No ping')
          return False

def _connect(ip):
     print('connect %s'%ip)
     subprocess.call('d:\psexec.exe \\\\%s cmd'%ip)
     return
def _fun(ip):
     #ip = input('in put ip here: \n')
     #if a == '': return
     _pingtest(ip)
     _checkhostname(ip)
     _connect(ip)
     return

def _checkhostname(ip):
     o = subprocess.getoutput('d:\psexec.exe \\\\%s hostname'%ip)
     p = o.find('www.sysinternals.com')
     o = o[p:]
     o = o.split('\n')
     name = o[2]
     if name=='' or name.find(' ')!= -1:
          print('[ + ] NO HOSTNAME RETURNED')
          return False
     else:
          print('[ + ] HOSTNAME = %s'%name)
          return True
def _printhelp():
     print('\ncheck\tlogin host\nc\tshort of check\nho\tcheck hostname\nh\thelp')
     return

def _quickcheck(ip,port):
     print('connect %s'%ip)
     flagping = _pingtest(ip)
     flaghost = _checkhostname(ip)
     if not (flagping or flaghost):
          print('[ + ] HOST NOT CONNECTED')
          return False
     o = subprocess.getoutput('d:\psexec.exe \\\\%s netstat -ano | findstr %s'%(ip,port))
     #print(type(o))
     if o == ' ':
          print('[ + ] PORT NOT FOUND')
          return
     print('[ + ] PORT LIST')
     o = o.split('\n')
     pidlist = []
     for i in o:
          if i.find(port) != -1:
               print(i)
               i = i.split(' ')
               pid = i[len(i)-1]
               if (pid not in pidlist) and int(pid)>5:
                    pidlist.append(pid)
     
     for i in pidlist:
          print('[ + ] TASK FOR PID %s'%i)
          o2 = subprocess.getoutput('d:\psexec.exe \\\\%s tasklist -v | findstr %s'%(ip,i))
          a = o2.split('\n')
          for j in a:
               if j.find(i) != -1:
                    print(j)
     return

def _telnet(ip,port=22):
     o = subprocess.getoutput('telnet %s %s'%(ip,port))
     print(o)
     return

print('welcome to use check scan\n')

COMMAND = {'check':_fun,'c':_fun,'ho':_checkhostname,'h':1,'help':_printhelp,'qu':_quickcheck,'telnet':_telnet}
flag = True
while flag:
     print('checkscan#',end='')
     co = input().split(' ')
     if co[0] == '':
          pass
     elif len(co) == 1:
          if co[0] == 'exit':
               print('[ + ] EXIT')
               break
          try:
               COMMAND.get(co[0])()
          except Exception as err:
               print(err)
     else:
          try:
               COMMAND.get(co[0])(*co[1:])
          except Exception as err:
               print(err)
     


0 0