Untitled

 avatar
unknown
plain_text
a year ago
1.8 kB
9
Indexable
class DNSRecord:
  def __init__ (self, hostname, ip_address):
    self.hostname=hostname
    self.ip_address=ip_address

class AddressTranslator:
  def __init__(self):
    self.addresses={"www.google.com":"142.251.32.36", "www.facebook.com":"157.240.22.35", "www.sfusd.edu":"23.185.0.3"}
  def translate_hostname(self,hostname):
    address=self.addresses.get(hostname)
    ip_address=DNSRecord(hostname, address)
    if ip_address:
      print(f"IP address for {hostname}:{ip_address}")
    else:
      print(f"{hostname} cannot be found")
  def add_translation(self, hostname, ip_address):
    self.new_hostname=input("please enter a new hostname: ")
    self.new_ip_address=input("Enter the corresponding IP address")
    addresses[new_hostname]=new_ip_address
    print(f"Hostname '{new_hostname}' is added to DNS directory")
  def delete_translation(self, hostname):
    if delete_hostname in addresses:
      del addresses[delete_hostname]
      print(f"Hostname {delete_hostname} is deleted from DNS")
    else:
      print(f"Hostname {delete_hostname} is not found in DNS")

address_translator=AddressTranslator()
main_menu=str(input("====ACCOUNT MENU====\n1. Translate a Hostname to an IP Address\n2. Add a Translation\n3. Delete a Translation\n4. Exit\n\nEnter Choice: "))
while main_menu!="4":
  if main_menu=="1":
    hostname=input("Please enter a hostname: ")
    address_translator.translate_hostname(hostname)
  if main_menu=="2":
    new_hostname=input("please enter a new hostname: ")
    new_ip_address=input("Enter the corresponding IP address")
    address_translator.add_translation(new_hostname, new_ip_address)
  if main_menu=="3":
    delete_hostname=input("please enter the hostname to delete: ")
    address_translator.delete_translation(delete_hostname)
  else:
    print("input is invalid")

print("thanks! Bye!")
  
Editor is loading...
Leave a Comment