← Playground

Added more python scripts

cc075c55cb12e555adb8a90cf7b58aaf777f28b0 · darakna · Dec 20, 2019 21:12

+439 −3 · 15 files changed

  • Pyton_stuff/Chapter_6_Strings/Strings.py +1 −1
  • Pyton_stuff/Wechall/Ackermann_Test1.py +13 −0
  • Pyton_stuff/Wechall/Test8.1_ping.py +12 −0
  • Pyton_stuff/Wechall/Test8_Ping.py +34 −0
  • Pyton_stuff/Wechall/Test9_Tracert.py +48 −0
  • Pyton_stuff/Wechall/romeo.txt +4 −0
  • Pyton_stuff/Wechall/socket_set_local_port.py +40 −0
  • Pyton_stuff/Wechall/test15_wechall_baconian.py +48 −0
  • Pyton_stuff/Work/List_dlls.py +1 −1
  • Pyton_stuff/caesar_and_tools/extended_caesar.py +1 −1
  • Pyton_stuff/sandbox_tests/Test10_Admin_rights.py +25 −0
  • Pyton_stuff/sandbox_tests/Test11_Hostnames_finder.py +144 −0
  • Pyton_stuff/sandbox_tests/Test12_Is_IP_Adress.py +32 −0
  • Pyton_stuff/sandbox_tests/Test13_Is_valid_domain.py +14 −0
  • Pyton_stuff/sandbox_tests/Test14_Get_Valid_ip_Addr.py +22 −0
diff --git a/Pyton_stuff/Chapter_6_Strings/Strings.py b/Pyton_stuff/Chapter_6_Strings/Strings.py
index 35bb58c..cc7ff29 100644
--- a/Pyton_stuff/Chapter_6_Strings/Strings.py
+++ b/Pyton_stuff/Chapter_6_Strings/Strings.py
@@ -1,4 +1,4 @@
-__author__ = 'vpaun'
+__author__ = 'darakna'
 r_file=open("LICENSE.txt",'r')
 w_file=open("out.txt",'w')
 w_file2=open("out2.txt",'w')
diff --git a/Pyton_stuff/Wechall/Ackermann_Test1.py b/Pyton_stuff/Wechall/Ackermann_Test1.py
new file mode 100644
index 0000000..80a66d6
--- /dev/null
+++ b/Pyton_stuff/Wechall/Ackermann_Test1.py
@@ -0,0 +1,13 @@
+__author__ = 'darakna'
+def ack(m,n):
+    print(m,n)
+    if m==0:
+        return n+1
+    elif m>0 and n==0:
+        return ack(m-1,1)
+    elif m>0 and n>0:
+        return ack(m-1,ack(m,n-1))
+    else:
+        print("Exception throw")
+
+print(ack(4,3))
\ No newline at end of file
diff --git a/Pyton_stuff/Wechall/Test8.1_ping.py b/Pyton_stuff/Wechall/Test8.1_ping.py
new file mode 100644
index 0000000..572f037
--- /dev/null
+++ b/Pyton_stuff/Wechall/Test8.1_ping.py
@@ -0,0 +1,12 @@
+__author__ = 'darakna'
+
+
+import os
+hostname = "www.k.ro" #example
+response = os.system("ping -n 1 " + hostname)
+
+#and then check the response...
+if response == 0:
+  print (hostname, 'is up!')
+else:
+  print (hostname, 'is down!')
\ No newline at end of file
diff --git a/Pyton_stuff/Wechall/Test8_Ping.py b/Pyton_stuff/Wechall/Test8_Ping.py
new file mode 100644
index 0000000..50f4b11
--- /dev/null
+++ b/Pyton_stuff/Wechall/Test8_Ping.py
@@ -0,0 +1,34 @@
+__author__ = 'darakna'
+from threading import Thread
+import subprocess
+from queue import *
+
+num_threads = 4
+queue = Queue()
+ips = ["k.ro", "8.8.8.8"]
+#wraps system ping command
+def pinger(i, q):
+    """Pings subnet"""
+    while True:
+        ip = q.get()
+        print("Thread %s: Pinging %s" % (i, ip))
+        ret = subprocess.call("ping -c 1 %s" % ip,
+            shell=True,
+            #tdout=open('/dev/null', 'w'),
+            stderr=subprocess.STDOUT)
+        if ret == 0:
+            print ("%s: is alive" % ip)
+        else:
+            print ("%s: did not respond" % ip)
+        q.task_done()
+#Spawn thread pool
+for i in range(num_threads):
+
+    worker = Thread(target=pinger, args=(i, queue))
+    worker.setDaemon(True)
+    worker.start()
+#Place work in queue
+for ip in ips:
+    queue.put(ip)
+#Wait until worker threads are done to exit
+queue.join()
\ No newline at end of file
diff --git a/Pyton_stuff/Wechall/Test9_Tracert.py b/Pyton_stuff/Wechall/Test9_Tracert.py
new file mode 100644
index 0000000..3b6e5b6
--- /dev/null
+++ b/Pyton_stuff/Wechall/Test9_Tracert.py
@@ -0,0 +1,48 @@
+__author__ = 'darakna'
+import socket
+
+def main(dest_name):
+    print("starting...")
+    dest_addr = socket.gethostbyname(dest_name)
+    port = 33434
+    max_hops = 30
+    icmp = socket.getprotobyname('icmp')
+    udp = socket.getprotobyname('udp')
+    ttl = 1
+    while True:
+        recv_socket = socket.socket(socket.AF_INET, socket.SOCK_RAW, icmp)
+        send_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, udp)
+        send_socket.setsockopt(socket.SOL_IP, socket.IP_TTL, ttl)
+        recv_socket.bind((b"", port))
+        send_socket.sendto(b"", (dest_name, port))
+        curr_addr = None
+        curr_name = None
+        print("trying...")
+        try:
+            _, curr_addr = recv_socket.recvfrom(512)
+            curr_addr = curr_addr[0]
+            print("more trying...")
+            try:
+                curr_name = socket.gethostbyaddr(curr_addr)[0]
+            except socket.error:
+                curr_name = curr_addr
+        except socket.error:
+            print("failing with: ...[%]" % socket.error)
+            pass
+        finally:
+            send_socket.close()
+            recv_socket.close()
+
+        if curr_addr is not None:
+            curr_host = "%s (%s)" % (curr_name, curr_addr)
+        else:
+            curr_host = "*"
+        print("%d\t%s" % (ttl, curr_host))
+
+        ttl += 1
+        if curr_addr == dest_addr or ttl > max_hops:
+            print("done...")
+            break
+
+if __name__ == "__main__":
+    main('8.8.8.8')
\ No newline at end of file
diff --git a/Pyton_stuff/Wechall/romeo.txt b/Pyton_stuff/Wechall/romeo.txt
new file mode 100644
index 0000000..e7abd44
--- /dev/null
+++ b/Pyton_stuff/Wechall/romeo.txt
@@ -0,0 +1,4 @@
+But soft what light through yonder window breaks
+It is the east and Juliet is the sun
+Arise fair sun and kill the envious moon
+Who is already sick and pale with grief
\ No newline at end of file
diff --git a/Pyton_stuff/Wechall/socket_set_local_port.py b/Pyton_stuff/Wechall/socket_set_local_port.py
new file mode 100644
index 0000000..29ab880
--- /dev/null
+++ b/Pyton_stuff/Wechall/socket_set_local_port.py
@@ -0,0 +1,40 @@
+# Echo client program
+import socket
+import sys
+
+HOST = 'www.wechall.net'    # The remote host
+local = ''
+cookie_vote = b"cookie_vote"
+cookie_WeChall= b"cookie_WeChall"
+req2 = b'GET https://www.wechall.net/challenge/training/net/ports/index.php HTTP/1.1\r\nHost: www.wechall.net\r\nCookie: VOTE=' + cookie_vote + b'; WC='+ cookie_WeChall + b'\r\n\r\n'
+PORT = 80            # The same port as used by the server
+local_port = 42
+s = None
+for res in socket.getaddrinfo(HOST, PORT, socket.AF_UNSPEC, socket.SOCK_STREAM):
+    af, socktype, proto, canonname, sa = res
+    try:
+        s = socket.socket(af, socktype, proto)
+    except socket.error as msg:
+        s = None
+        continue
+    try:
+        s.bind(('',local_port))
+        s.connect(sa)
+    except socket.error as msg:
+        s.close()
+        s = None
+        continue
+    break
+if s is None:
+    print('could not open socket')
+    sys.exit(1)
+s.sendall(req2)
+data = s.recv(10240)
+data2 = s.recv(10240)
+data3 = s.recv(10240)
+data4 = s.recv(10240)
+s.close()
+print('Received', data.decode())
+print('Received2', data2.decode())
+print('Received3', data3.decode())
+print('Received4', data4.decode())
\ No newline at end of file
diff --git a/Pyton_stuff/Wechall/test15_wechall_baconian.py b/Pyton_stuff/Wechall/test15_wechall_baconian.py
new file mode 100644
index 0000000..bfdabf3
--- /dev/null
+++ b/Pyton_stuff/Wechall/test15_wechall_baconian.py
@@ -0,0 +1,48 @@
+def namestr(obj, namespace):
+    return [name for name in namespace if namespace[name] is obj]
+
+
+bacon_string = "BaCoN's cIphEr or THE bacOnIAN CiPHer iS a meThOD oF sTEGaNOGrapHY (a METhoD Of HidIng A sECRet MeSsaGe as OpPOsEd TO a TRUe CiPHeR) dEVIseD BY francis bAcoN. a MessAge Is coNCeALED in THe pRESenTatIoN OF TexT, ratHer thaN iTs coNteNt. tO enCODe A MEsSaGe, eaCh lETter Of THe pLAInText Is rePLAcED By A groUp oF fIvE OF tHe LETterS 'a' or 'b'. ThIs REplACeMenT iS doNe acCOrdIng to tHE alPhABet of tHe BACOnIAN cIpHeR, sHoWn bElOw. NoTe: A SeCoNd vErSiOn oF BaCoN'S CiPhEr uSeS A UnIqUe cOdE FoR EaCh lEtTeR. iN OtHeR WoRdS, i aNd j eAcH HaS ItS OwN PaTtErN. tHe wRiTeR MuSt mAkE UsE Of tWo dIfFeReNt tYpEfAcEs fOr tHiS CiPhEr. AfTeR PrEpArInG A FaLsE MeSsAgE WiTh tHe sAmE NuMbEr oF LeTtErS As aLl oF ThE As aNd bS In tHe rEaL, sEcReT MeSsAgE, tWo tYpEfAcEs aRe cHoSeN, oNe tO RePrEsEnT As aNd tHe oThEr bS. tHeN EaCh lEtTeR Of tHe fAlSe mEsSaGe mUsT Be pReSeNtEd iN ThE ApPrOpRiAtE TyPeFaCe, AcCoRdInG To wHeThEr iT StAnDs fOr aN A Or a b. To dEcOdE ThE MeSsAgE, tHe rEvErSe mEtHoD Is aPpLiEd. EaCh 'TyPeFaCe 1' LeTtEr iN ThE FaLsE MeSsAgE Is rEpLaCeD WiTh aN A AnD EaCh 'TyPeFaCe 2' LeTtEr iS RePlAcEd wItH A B. tHe bAcOnIaN AlPhAbEt iS ThEn uSeD To rEcOvEr tHe oRiGiNaL MeSsAgE. aNy mEtHoD Of wRiTiNg tHe mEsSaGe tHaT AlLoWs tWo dIsTiNcT RePrEsEnTaTiOnS FoR EaCh cHaRaCtEr cAn bE UsEd fOr tHe bAcOn cIpHeR. bAcOn hImSeLf pRePaReD A BiLiTeRaL AlPhAbEt[2] FoR HaNdWrItTeN CaPiTaL AnD SmAlL LeTtErS WiTh eAcH HaViNg tWo aLtErNaTiVe fOrMs, OnE To bE UsEd aS A AnD ThE OtHeR As b. ThIs wAs pUbLiShEd aS An iLlUsTrAtEd pLaTe iN HiS De aUgMeNtIs sCiEnTiArUm (ThE AdVaNcEmEnT Of lEaRnInG). BeCaUsE AnY MeSsAgE Of tHe rIgHt lEnGtH CaN Be uSeD To cArRy tHe eNcOdInG, tHe sEcReT MeSsAgE Is eFfEcTiVeLy hIdDeN In pLaIn sIgHt. ThE FaLsE MeSsAgE CaN Be oN AnY ToPiC AnD ThUs cAn dIsTrAcT A PeRsOn sEeKiNg tO FiNd tHe rEaL MeSsAgE."
+bacon_proc1 = ""
+bacon_proc2 = ""
+for letter in bacon_string:
+    if letter >= "A" and letter <= "Z":
+        bacon_proc1 = bacon_proc1 + "A"
+        #bacon_proc2 = bacon_proc2 + "B"
+    elif letter >= "a" and letter <= "z":
+        bacon_proc1 = bacon_proc1 + "B"
+        #bacon_proc2 = bacon_proc2 + "A"
+    else:
+        pass
+        #bacon_proc1 = bacon_proc1 + letter
+        #bacon_proc2 = bacon_proc2 + letter
+processed_bacon_proc1 = ""
+processed_bacon_proc2 = ""
+dict = {"AAAAA" : "a", "AABBA" : "g", "ABBAA" : "n", "BAABA" : "t", "AAAAB" : "b", "AABBB" : "h", "ABBAB" : "o", "BAABB" : "v", "AAABA" : "c", "ABAAA" : "i", "ABBBA" : "p", "BABAA" : "w", "AAABB" : "d", "ABAAB" : "k", "ABBBB" : "q", "BABAB" : "x", "AABAA" : "e", "ABABA" : "l", "BAAAA" : "r", "BABBA" : "y", "AABAB" : "f", "ABABB" : "m", "BAAAB" : "s", "BABBB" : "z"}
+dict2 = {}
+print(bacon_proc1)
+#print(bacon_proc2)
+num = 0
+letter = 1
+while num <= int(len(bacon_proc1)/5):
+    if bacon_proc1[num*5:(num + 1)*5] in dict:
+        processed_bacon_proc1 = processed_bacon_proc1 + dict[bacon_proc1[num*5:(num + 1)*5]]
+    else:
+        pass
+        #processed_bacon_proc1 = processed_bacon_proc1 + bacon_proc1[num*5:(num + 1)*5]
+
+    if bacon_proc2[num * 5:(num + 1) * 5] in dict:
+        processed_bacon_proc2 = processed_bacon_proc2 + dict[bacon_proc2[num * 5:(num + 1) * 5]]
+    else:
+        processed_bacon_proc2 = processed_bacon_proc2 + bacon_proc2[num * 5:(num + 1) * 5]
+    if bacon_proc1[num*5:(num + 1)*5] not in dict2:
+        dict2[bacon_proc1[num*5:(num + 1)*5]] = letter
+        letter += 1
+    num += 1
+print(processed_bacon_proc1)
+#print(processed_bacon_proc2)
+print(dict)
+print(dict2, letter)
+
+
+
diff --git a/Pyton_stuff/Work/List_dlls.py b/Pyton_stuff/Work/List_dlls.py
index 66f157f..e01311d 100644
--- a/Pyton_stuff/Work/List_dlls.py
+++ b/Pyton_stuff/Work/List_dlls.py
@@ -1,4 +1,4 @@
-__author__ = 'vpaun'
+__author__ = 'darakna'
 import os
 pid_name="calc.exe"
 tmp_location="D:\DllsList.txt"
diff --git a/Pyton_stuff/caesar_and_tools/extended_caesar.py b/Pyton_stuff/caesar_and_tools/extended_caesar.py
index b04950e..efcbe77 100644
--- a/Pyton_stuff/caesar_and_tools/extended_caesar.py
+++ b/Pyton_stuff/caesar_and_tools/extended_caesar.py
@@ -1,4 +1,4 @@
-__author__ = 'vpaun'
+__author__ = 'darakna'
 import sys
 # table of probabilities for each letter
 def letProb( c ):
diff --git a/Pyton_stuff/sandbox_tests/Test10_Admin_rights.py b/Pyton_stuff/sandbox_tests/Test10_Admin_rights.py
new file mode 100644
index 0000000..3687950
--- /dev/null
+++ b/Pyton_stuff/sandbox_tests/Test10_Admin_rights.py
@@ -0,0 +1,25 @@
+__author__ = 'darakna'
+def elevate():
+    import ctypes, win32com.shell.shell, win32event, win32process
+    outpath = r'%s\%s.out' % (os.environ["TEMP"], os.path.basename(__file__))
+    if ctypes.windll.shell32.IsUserAnAdmin():
+        if os.path.isfile(outpath):
+            sys.stderr = sys.stdout = open(outpath, 'w', 0)
+        return
+    with open(outpath, 'w+', 0) as outfile:
+        hProc = win32com.shell.shell.ShellExecuteEx(lpFile=sys.executable,
+            lpVerb='runas', lpParameters=' '.join(sys.argv), fMask=64, nShow=0)['hProcess']
+        while True:
+            hr = win32event.WaitForSingleObject(hProc, 40)
+            while True:
+                line = outfile.readline()
+                if not line: break
+                sys.stdout.write(line)
+            if hr != 0x102: break
+    os.remove(outpath)
+    sys.stderr = ''
+    sys.exit(win32process.GetExitCodeProcess(hProc))
+
+if __name__ == '__main__':
+    elevate()
+    main()
\ No newline at end of file
diff --git a/Pyton_stuff/sandbox_tests/Test11_Hostnames_finder.py b/Pyton_stuff/sandbox_tests/Test11_Hostnames_finder.py
new file mode 100644
index 0000000..789e014
--- /dev/null
+++ b/Pyton_stuff/sandbox_tests/Test11_Hostnames_finder.py
@@ -0,0 +1,144 @@
+__author__ = 'darakna'
+from socket import *
+import socket
+fname = ""# input("Enter file name: ")
+ip_valid = open('ip_valid.txt','w')
+hostname_valid=open('hostname_valid.txt','w')
+if fname!="mbox-short.txt":
+    fname="mbox-short.txt"
+fh = open(fname)
+TLD=open("TLD_suffix.txt")
+TLD_words=TLD.read()
+domain_char_list=list(range(45,47))+list(range(48,58))+list(range(65,91))+list(range(97,123))
+lcounter=0
+dcounter=0
+wcounter=0
+wdcounter=0
+wdpcounter=0
+wordlist={}
+domain_dict={}
+hostnames=[]
+ips=[]
+def discover_superdomains(words):
+    while words.count(".")>=1:
+        print(words,newword,is_valid_domain(words),is_valid_ip(words))
+        if is_valid_domain_verify(words):
+            wordlist[is_valid_domain_verify(words)]=words
+            words=domain_short(words)
+
+def define_domain_dict():
+    res = {}
+    ord=0
+    with open("TLD_suffix.txt","r") as text:
+        for line in text:
+            value = line
+            res[line[:-1]] = value[:-1]
+            ord=ord+1
+    return res
+domain_dict=define_domain_dict()
+def is_valid_ipv4_address(address):
+    try:
+        socket.inet_pton(socket.AF_INET, address)
+    except AttributeError:  # no inet_pton here, sorry
+        try:
+            socket.inet_aton(address)
+        except socket.error:
+            return False
+        return address.count('.') == 3
+    except socket.error:  # not a valid address
+        return False
+
+    return True
+
+def is_valid_ipv6_address(address):
+    try:
+        socket.inet_pton(socket.AF_INET6, address)
+    except socket.error:  # not a valid address
+        return False
+    return True
+def is_valid_ip(ip):
+    """Validates IP addresses.
+    """
+    return is_valid_ipv4_address(ip) or is_valid_ipv6_address(ip)
+def is_valid_domain(adress):
+    dpos=adress.rfind(".")
+    if adress[dpos+1:]=="":
+        return False
+    if adress[dpos+1:].upper() in domain_dict:
+        return True
+    else:
+        return False
+def ip_has_domain(ip):
+    try:
+        name, alias, addresslist = socket.gethostbyaddr(ip)
+    except:
+        name=False
+    return name
+def stripall(word):
+    if word=="":
+        return ""
+    else:
+        if ord(word[0]) in domain_char_list:
+            return word[0]+stripall(word[1:])
+        else:
+            return stripall(word[1:])
+def stripdomain(dword):
+    tp=dword[dword.index("://")+3:]
+    tp=tp[:tp.index("/")]
+    return tp
+#from socket import getaddrinfo
+#import socket
+
+def is_valid_domain_verify(name):
+    try:
+        result = getaddrinfo(name, None)
+        result=result[0][4][0]
+    except:
+        result="Fail"
+    return (result)
+def domain_short(words):
+    return words[words.index(".")+1:]
+for line in fh:
+    lcounter=lcounter+1
+    if "." not in line:
+        continue
+    for words in line.split():
+        wcounter=wcounter+1
+        if "." not in words:
+            continue
+        wdcounter=wdcounter+1
+        newword="???!!!???"
+        if "@" in words:
+            newword=words
+            words=words[words.index("@")+1:]
+            wdpcounter=wdpcounter+1
+        if "://" in words:
+            newword=words
+            words=stripdomain(words)
+        newword=words
+        words=stripall(words)
+        if  is_valid_ip(words):
+            if words not in ips:
+                ips.append(words)
+                ip_valid.write(words+"\n")
+        elif is_valid_domain(words):
+            if words not in hostnames:
+                hostnames.append(words)
+                hostname_valid.write(words+"\n")
+            #if words not in wordlist:
+                #if is_valid_ip(words):
+                #    print(words,newword,is_valid_domain(words),is_valid_ip(words))
+                #    if ip_has_domain(words):
+                #        discover_superdomains(ip_has_domain(words))
+                    #wordlist[words]="No_Valid_Domain"
+                #elif is_valid_domain(words):
+                 #   discover_superdomains(words)
+            print(words)
+
+    pos=line.find(".")
+    #print(line)
+    dcounter=dcounter+1
+for key in wordlist:
+    print(wordlist[key]," "*(50-len(wordlist[key])),key)
+print(lcounter,dcounter,wcounter,wdcounter,wdpcounter)
+#print(TLD_words)
\ No newline at end of file
diff --git a/Pyton_stuff/sandbox_tests/Test12_Is_IP_Adress.py b/Pyton_stuff/sandbox_tests/Test12_Is_IP_Adress.py
new file mode 100644
index 0000000..1d5fcb4
--- /dev/null
+++ b/Pyton_stuff/sandbox_tests/Test12_Is_IP_Adress.py
@@ -0,0 +1,32 @@
+__author__ = 'darakna'
+import socket
+def is_valid_ipv4_address(address):
+    try:
+        socket.inet_pton(socket.AF_INET, address)
+    except AttributeError:  # no inet_pton here, sorry
+        try:
+            socket.inet_aton(address)
+        except socket.error:
+            return False
+        return address.count('.') == 3
+    except socket.error:  # not a valid address
+        return False
+
+    return True
+
+def is_valid_ipv6_address(address):
+    try:
+        socket.inet_pton(socket.AF_INET6, address)
+    except socket.error:  # not a valid address
+        return False
+    return True
+def is_valid_ip(ip):
+    """Validates IP addresses.
+    """
+    return is_valid_ipv4_address(ip) or is_valid_ipv6_address(ip)
+
+
+print(is_valid_ip("192.168.0.0"))
+print(is_valid_ip("292.168.0.0"))
+print(is_valid_ip("4"))
+print(is_valid_ipv4_address("0.6959"))
\ No newline at end of file
diff --git a/Pyton_stuff/sandbox_tests/Test13_Is_valid_domain.py b/Pyton_stuff/sandbox_tests/Test13_Is_valid_domain.py
new file mode 100644
index 0000000..2d1a1d9
--- /dev/null
+++ b/Pyton_stuff/sandbox_tests/Test13_Is_valid_domain.py
@@ -0,0 +1,14 @@
+__author__ = 'darakna'
+TLD=open("TLD_suffix.txt")
+TLD_words=TLD.read()
+def is_valid_domain(adress):
+    dpos=adress.rfind(".")
+    #print(dpos,adress[dpos+1:])
+    if adress[dpos+1:].upper() in TLD_words:
+        return True
+    else:
+        return False
+
+print(is_valid_domain("app1.prod.collab.uhi.ac.uk"))
+print(is_valid_domain("v2.2.12"))
+print(is_valid_domain("8.12.11.200603088.12.11Submit"))
diff --git a/Pyton_stuff/sandbox_tests/Test14_Get_Valid_ip_Addr.py b/Pyton_stuff/sandbox_tests/Test14_Get_Valid_ip_Addr.py
new file mode 100644
index 0000000..e42cbf5
--- /dev/null
+++ b/Pyton_stuff/sandbox_tests/Test14_Get_Valid_ip_Addr.py
@@ -0,0 +1,22 @@
+__author__ = 'darakna'
+from socket import getaddrinfo
+import socket
+
+def is_valid_domain(name):
+    try:
+        result = getaddrinfo(name, None)
+        result=result[0][4][0]
+    except:
+        result="Fail"
+    return (result)
+print(is_valid_domain("app1.prod.collab.uhi.ac.uk"))
+print(is_valid_domain("prod.collab.uhi.ac.uk"))
+print(is_valid_domain("collab.uhi.ac.uk"))
+print(is_valid_domain("uhi.ac.uk"))
+print(is_valid_domain("ac.uk"))
+a=getaddrinfo("8.8.8.8",None)
+print(a)
+
+#import socket
+name, alias, addresslist = socket.gethostbyaddr('8.8.8.8')
+print(name)
\ No newline at end of file