Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import infoblox # Infoblox API import
- import getpass # To hide user password input
- import certifi
- def infobloxAddHost(username, password, domainName, ipAddress):
- iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
- try:
- ip = iba_api.create_host_record(str(ipAddress), str(domainName))
- print(ip)
- except Exception as e:
- print(e)
- def infobloxAddCname(username, password, domainName, canonicalName):
- iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
- def infobloxAddTxt(username, password, domainName, txtInfo):
- iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
- def infobloxDelHost(username, password, domainName, ipAddress):
- iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
- def infobloxDelCname(username, password, domainName, canonicalName):
- iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
- def infobloxDelTxt(username, password, domainName):
- iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
- ##########################################################################################################################################
- ############################################ This is the master function for the DNS project #############################################
- ##########################################################################################################################################
- def mainMenu():
- # welcome
- print("What would you like to do?\n")
- print("1. Add Host Record\n")
- print("2. Add CNAME Record\n")
- print("3. Add TXT Record\n")
- print("4. Delete Host Record\n")
- print("5. Delete CNAME Record\n")
- print("6. Delete TXT Record\n")
- userChoice = input("> ")
- if int(userChoice) == 1:
- addHostRecord()
- elif userChoice == 2:
- raise SystemExit
- ##########################################################################################################################################
- ################################################### If the user wants to add Host Record ####################################################
- ##########################################################################################################################################
- def addHostRecord():
- print("Please enter the domain name\n")
- domainName = input("> ")
- print("Please enter the IP address\n")
- ipAddress = input("> ")
- print("\nPlease confirm creating the following Host record (y/n):\n")
- print("Domain Name: " + domainName + "\n")
- print("IP Address: " + ipAddress + "\n")
- confirmChoice = input("> ")
- if confirmChoice in ['y', 'Y', 'yes', 'yeS', 'yEs', 'yES', 'Yes', 'YeS', 'YEs', 'YES']:
- print("\n")
- print("Please enter your Directory ID\n")
- username = input("> ")
- print("Please enter your Directory PW\n")
- password = getpass.getpass("> ")
- infobloxAddHost(username, password, domainName, ipAddress)
- elif confirmChoice in ['n', 'N', 'no', 'No', 'nO', 'NO']:
- print("\n")
- print("Host record creation canceled. What would you like to do?\n")
- menuOptions()
- ##########################################################################################################################################
- ################################################# If the user wants to add CNAME Record ##################################################
- ##########################################################################################################################################
- def addCNAME():
- print("Please enter the domain name\n")
- domainName = input("> ")
- print("Please enter the canonical name\n")
- canonicalName = input("> ")
- print("\nPlease confirm creating the following CNAME record (y/n):\n")
- print("Domain Name: " + domainName + "\n")
- print("IP Address: " + canonicalName + "\n")
- confirmChoice = input("> ")
- if confirmChoice in ['y', 'Y', 'yes', 'yeS', 'yEs', 'yES', 'Yes', 'YeS', 'YEs', 'YES']:
- print("\n")
- print("Please enter your Directory ID\n")
- username = input("> ")
- print("Please enter your Directory PW\n")
- password = getpass.getpass("> ")
- infobloxAddCname(username, password, domainName, canonicalName)
- elif confirmChoice in ['n', 'N', 'no', 'No', 'nO', 'NO']:
- print("\n")
- print("CNAME record creation canceled. What would you like to do?\n")
- menuOptions()
- ##########################################################################################################################################
- ################################################ Cleanup Code to Quit or Go To Main Menu #################################################
- ##########################################################################################################################################
- def menuOptions():
- while True:
- print("1. Return to the main menu\n")
- print("2. Quit the program\n")
- userChoice = input("> ")
- if userChoice == 1:
- mainMenu()
- elif userChoice == 2:
- print("Thank you for using KW's DNS program!")
- raise SystemExit
- else:
- print("Please choose a valid selection.")
- continue
- mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement