Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.44 KB | None | 0 0
  1. import infoblox # Infoblox API import
  2. import getpass # To hide user password input
  3. import certifi
  4.  
  5.  
  6. def infobloxAddHost(username, password, domainName, ipAddress):
  7.  
  8. iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
  9. try:
  10. ip = iba_api.create_host_record(str(ipAddress), str(domainName))
  11. print(ip)
  12. except Exception as e:
  13. print(e)
  14.  
  15.  
  16. def infobloxAddCname(username, password, domainName, canonicalName):
  17. iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
  18.  
  19.  
  20.  
  21. def infobloxAddTxt(username, password, domainName, txtInfo):
  22. iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
  23.  
  24.  
  25.  
  26. def infobloxDelHost(username, password, domainName, ipAddress):
  27. iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
  28.  
  29.  
  30.  
  31. def infobloxDelCname(username, password, domainName, canonicalName):
  32. iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
  33.  
  34.  
  35.  
  36. def infobloxDelTxt(username, password, domainName):
  37. iba_api = infoblox.Infoblox('X.X.X.X', username, password, '2.1', 'internal', 'default', False)
  38.  
  39.  
  40. ##########################################################################################################################################
  41. ############################################ This is the master function for the DNS project #############################################
  42. ##########################################################################################################################################
  43.  
  44.  
  45. def mainMenu():
  46. # welcome
  47.  
  48. print("What would you like to do?\n")
  49. print("1. Add Host Record\n")
  50. print("2. Add CNAME Record\n")
  51. print("3. Add TXT Record\n")
  52. print("4. Delete Host Record\n")
  53. print("5. Delete CNAME Record\n")
  54. print("6. Delete TXT Record\n")
  55. userChoice = input("> ")
  56.  
  57. if int(userChoice) == 1:
  58. addHostRecord()
  59. elif userChoice == 2:
  60. raise SystemExit
  61.  
  62. ##########################################################################################################################################
  63. ################################################### If the user wants to add Host Record ####################################################
  64. ##########################################################################################################################################
  65.  
  66. def addHostRecord():
  67.  
  68. print("Please enter the domain name\n")
  69. domainName = input("> ")
  70. print("Please enter the IP address\n")
  71. ipAddress = input("> ")
  72. print("\nPlease confirm creating the following Host record (y/n):\n")
  73. print("Domain Name: " + domainName + "\n")
  74. print("IP Address: " + ipAddress + "\n")
  75. confirmChoice = input("> ")
  76. if confirmChoice in ['y', 'Y', 'yes', 'yeS', 'yEs', 'yES', 'Yes', 'YeS', 'YEs', 'YES']:
  77. print("\n")
  78. print("Please enter your Directory ID\n")
  79. username = input("> ")
  80. print("Please enter your Directory PW\n")
  81. password = getpass.getpass("> ")
  82. infobloxAddHost(username, password, domainName, ipAddress)
  83. elif confirmChoice in ['n', 'N', 'no', 'No', 'nO', 'NO']:
  84. print("\n")
  85. print("Host record creation canceled. What would you like to do?\n")
  86. menuOptions()
  87.  
  88. ##########################################################################################################################################
  89. ################################################# If the user wants to add CNAME Record ##################################################
  90. ##########################################################################################################################################
  91.  
  92. def addCNAME():
  93. print("Please enter the domain name\n")
  94. domainName = input("> ")
  95. print("Please enter the canonical name\n")
  96. canonicalName = input("> ")
  97. print("\nPlease confirm creating the following CNAME record (y/n):\n")
  98. print("Domain Name: " + domainName + "\n")
  99. print("IP Address: " + canonicalName + "\n")
  100. confirmChoice = input("> ")
  101. if confirmChoice in ['y', 'Y', 'yes', 'yeS', 'yEs', 'yES', 'Yes', 'YeS', 'YEs', 'YES']:
  102. print("\n")
  103. print("Please enter your Directory ID\n")
  104. username = input("> ")
  105. print("Please enter your Directory PW\n")
  106. password = getpass.getpass("> ")
  107. infobloxAddCname(username, password, domainName, canonicalName)
  108. elif confirmChoice in ['n', 'N', 'no', 'No', 'nO', 'NO']:
  109. print("\n")
  110. print("CNAME record creation canceled. What would you like to do?\n")
  111. menuOptions()
  112.  
  113. ##########################################################################################################################################
  114. ################################################ Cleanup Code to Quit or Go To Main Menu #################################################
  115. ##########################################################################################################################################
  116.  
  117. def menuOptions():
  118.  
  119. while True:
  120. print("1. Return to the main menu\n")
  121. print("2. Quit the program\n")
  122. userChoice = input("> ")
  123. if userChoice == 1:
  124. mainMenu()
  125. elif userChoice == 2:
  126. print("Thank you for using KW's DNS program!")
  127. raise SystemExit
  128. else:
  129. print("Please choose a valid selection.")
  130. continue
  131.  
  132. mainMenu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement