diff --git a/Codes/Code-C10.py b/Codes/Code-C10.py new file mode 100644 index 0000000..db80765 --- /dev/null +++ b/Codes/Code-C10.py @@ -0,0 +1,26 @@ +import socket + +def dns_lookup(): + choice = input("Choose an operation:\n1 -> lookup a URL\n2 -> lookup an IP address\nEnter choice (1/2):\t") + + if choice == '1': + url = input("Enter the URL (e.g. kska.io): ") + try: + ip_address = socket.gethostbyname(url) + print(f"The IP address for {url} is: {ip_address}") + except socket.gaierror: + print("Error: Unable to resolve the URL.") + + elif choice == '2': + ip_address = input("Enter the IP address (e.g. 93.184.216.34): ") + try: + url = socket.gethostbyaddr(ip_address)[0] + print(f"The URL for {ip_address} is: {url}") + except socket.herror: + print("Error: Unable to resolve the IP address.") + + else: + print("Invalid choice. Please enter 1 or 2.") + +if __name__ == "__main__": + dns_lookup() diff --git a/Printable outputs/Output-C10.pdf b/Printable outputs/Output-C10.pdf new file mode 100644 index 0000000..0968f44 Binary files /dev/null and b/Printable outputs/Output-C10.pdf differ diff --git a/README.md b/README.md index f81011d..4be8987 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,9 @@ This Git repository is a comprehensive resource for the Computer Networks and Se - [Output-B9](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-B9.pdf) ##### C10 - DNS +- [Code-C10](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Codes/Code-C10.py) - [Handout-C10](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Handouts/Handout-C10.pdf) +- [Output-C10](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Printable%20outputs/Output-C10.pdf) ##### C11 - DHCP - [Handout-C11](https://git.kska.io/sppu-te-comp-content/ComputerNetworksAndSecurity/src/branch/main/Handouts/Handout-C11.pdf)