Guest User

Untitled

a guest
May 26th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. from fabric import Connection
  2. from invoke import task
  3. import dns.resolver
  4. import ipaddress
  5. import sys
  6.  
  7.  
  8. @task
  9. def Wbox(cnt,domain,host=False,user=None):
  10. cnt.domain = domain
  11. cnt.ip = find_host(domain,A=True)
  12. cnt.host = domain if host else find_host(domain)[0]
  13.  
  14. print "Domain:\t\t{}\nIP Address:\t{}\nHostname:\t{}".format(cnt.domain,cnt.ip,cnt.host)
  15.  
  16. if not any("webhostbox.net" in s for s in find_host(cnt.domain)) and not host:
  17. print "{}Host is not a webhostbox.net hostname ;(".format(cnt.host)
  18. inRput = raw_input("Please Enter the server Hostname/IP to continue:")
  19. cnt.host = inRput if inRput != '' else sys.exit(0)
  20. print "Hostname: \t{}".format(cnt.host)
  21. try:
  22. cnt.user = Connection(cnt.host).sudo("/scripts/whoowns "+ cnt.domain, hide=True).stdout.strip() if not host else user
  23. except:
  24. print "Error Trying to find Username for {} on {}".format(cnt.domain,cnt.host)
  25. cnt.user = user
  26. print "user:\t\t{}".format(cnt.user)
  27.  
  28.  
  29.  
  30.  
  31.  
  32. @task
  33. def Mpw(cnt,domain,Area=None,log_type=None):
  34. if loc == 'aus':
  35.  
  36. cmd = "grep {} {}".format(keyWord,logFile)
  37. try:
  38. Connection("kafka").run(cmd)
  39. except Exception as e:
  40. print "could not find any log"
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. def find_host(domain,A=False,MX=False):
  50. result=[]
  51. myResolver = dns.resolver.Resolver()
  52. myResolver.nameservers = ['8.8.8.8', '8.8.4.4']
  53. if is_ip(domain):
  54. IP = domain
  55. if A:
  56. return IP
  57. else:
  58. if MX:
  59. try:
  60. myAnswers = myResolver.query(req, "MX")
  61. for rdata in myAnswers:
  62. result.append(str(rdata))
  63. return result
  64. except Exception as e:
  65. print e
  66. return None
  67.  
  68. try:
  69. resp = myResolver.query(domain ,'A')
  70. except Exception as e:
  71. return None
  72. if A:
  73. for ip in resp:
  74. return str(ip)
  75. else:
  76. for ip in resp:
  77. IP = ip
  78. req = '.'.join(reversed(str(IP).split("."))) + ".in-addr.arpa"
  79. try:
  80. myAnswers = myResolver.query(req, "PTR")
  81. for rdata in myAnswers:
  82. result.append(str(rdata))
  83. return result
  84. except Exception as e:
  85. print e
  86. return None
  87.  
  88.  
  89.  
  90.  
  91.  
  92. def is_ip(ip_addr):
  93. try:
  94. ip = ipaddress.ip_address(unicode(ip_addr, "utf-8"))
  95. return True
  96. except:
  97. return False
Add Comment
Please, Sign In to add comment