Guest User

Untitled

a guest
Nov 18th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. #coding=utf-8
  2. import platform
  3. import sys
  4. import os
  5. import time
  6. import thread
  7.  
  8. def get_os():
  9. '''
  10. get os 类型
  11. '''
  12. os = platform.system()
  13. if os == "Windows":
  14. return "n"
  15. else:
  16. return "c"
  17.  
  18. def ping_ip(ip_str):
  19. cmd = ["ping", "-{op}".format(op=get_os()),
  20. "1", ip_str]
  21. output = os.popen(" ".join(cmd)).readlines()
  22.  
  23. flag = False
  24. for line in list(output):
  25. if not line:
  26. continue
  27. if str(line).upper().find("TTL") >=0:
  28. flag = True
  29. break
  30. if flag:
  31. print "ip: %s is ok ***"%ip_str
  32.  
  33. def find_ip(ip_prefix):
  34. '''
  35. 给出当前的127.0.0 ,然后扫描整个段所有地址
  36. '''
  37. for i in range(1,256):
  38. ip = '%s.%s'%(ip_prefix,i)
  39. thread.start_new_thread(ping_ip, (ip,))
  40. time.sleep(0.3)
  41.  
  42. if __name__ == "__main__":
  43. print "start time %s"%time.ctime()
  44. commandargs = sys.argv[1:]
  45. args = "".join(commandargs)
  46.  
  47. ip_prefix = '.'.join(args.split('.')[:-1])
  48. find_ip(ip_prefix)
  49. print "end time %s"%time.ctime()
Add Comment
Please, Sign In to add comment