Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from fabric import Connection
- from invoke import task
- import dns.resolver
- import ipaddress
- import sys
- @task
- def Wbox(cnt,domain,host=False,user=None):
- cnt.domain = domain
- cnt.ip = find_host(domain,A=True)
- cnt.host = domain if host else find_host(domain)[0]
- print "Domain:\t\t{}\nIP Address:\t{}\nHostname:\t{}".format(cnt.domain,cnt.ip,cnt.host)
- if not any("webhostbox.net" in s for s in find_host(cnt.domain)) and not host:
- print "{}Host is not a webhostbox.net hostname ;(".format(cnt.host)
- inRput = raw_input("Please Enter the server Hostname/IP to continue:")
- cnt.host = inRput if inRput != '' else sys.exit(0)
- print "Hostname: \t{}".format(cnt.host)
- try:
- cnt.user = Connection(cnt.host).sudo("/scripts/whoowns "+ cnt.domain, hide=True).stdout.strip() if not host else user
- except:
- print "Error Trying to find Username for {} on {}".format(cnt.domain,cnt.host)
- cnt.user = user
- print "user:\t\t{}".format(cnt.user)
- @task
- def Mpw(cnt,domain,Area=None,log_type=None):
- if loc == 'aus':
- cmd = "grep {} {}".format(keyWord,logFile)
- try:
- Connection("kafka").run(cmd)
- except Exception as e:
- print "could not find any log"
- def find_host(domain,A=False,MX=False):
- result=[]
- myResolver = dns.resolver.Resolver()
- myResolver.nameservers = ['8.8.8.8', '8.8.4.4']
- if is_ip(domain):
- IP = domain
- if A:
- return IP
- else:
- if MX:
- try:
- myAnswers = myResolver.query(req, "MX")
- for rdata in myAnswers:
- result.append(str(rdata))
- return result
- except Exception as e:
- print e
- return None
- try:
- resp = myResolver.query(domain ,'A')
- except Exception as e:
- return None
- if A:
- for ip in resp:
- return str(ip)
- else:
- for ip in resp:
- IP = ip
- req = '.'.join(reversed(str(IP).split("."))) + ".in-addr.arpa"
- try:
- myAnswers = myResolver.query(req, "PTR")
- for rdata in myAnswers:
- result.append(str(rdata))
- return result
- except Exception as e:
- print e
- return None
- def is_ip(ip_addr):
- try:
- ip = ipaddress.ip_address(unicode(ip_addr, "utf-8"))
- return True
- except:
- return False
Add Comment
Please, Sign In to add comment