Python Forum

Full Version: Please help me with my Bootcamp Homework...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Here are the Instructions I have been given...

## Unit 3 Homework Assignment: Intro to Python Programming

In this homework assignment, you will be using the concepts you've learned in class to complete the below two activities.

---
## DNS Dictionary

As a network admin, you've been given a list of DNS server IPs and their providers in two separate lists. Your company needs these in an accessible form in order to verify the DNS server IP and provider together in case malware alters company machines' IP configurations to use a rogue DNS server.

In order to look up a DNS server IP using the provider name, you'll need to build a way to put that information together, similar to a phone book.

Your goal is to build different data structures for easily accessing information associated with these DNS properties.

### Instructions

Open up the Unsolved/DNSDictionary.py file. For each step, accomplish the following:

1. Use a for loop to create a dictionary mapping the provider names to their IPs.

- For example, two entries in the dictionary would look like:


        {
            'Level3': '209.244.0.3',
            'Verisign': '64.6.64.6'
        }
- Print Hurricane Electric's IPs using the dictionary.

2. Use a for loop to create a list of dictionaries with the associated information.

- For example, two entries in the list would look like:


        [
            {
                'provider_name': 'Level3',
                'primary_server': '209.244.0.3'
            },
            {
                'provider_name': 'Verisign',
                'primary_server': '64.6.64.6'
            }
        ]
- Print the total number of providers using the list.

### Bonuses

3. Use a for loop to update your dictionary from part 1 with the new IPs.

- For example, two entries in the dictionary would look like:


        {
            'Level3': ['209.244.0.3', '209.244.0.4'],
            'Verisign': ['64.6.64.6', '64.6.65.6']
        }
- The IPs should be in the form of an array of IPs.

- Print Google's IPs using the dictionary.

4. Use nested for loops to update the list from part 2 with a 'secondary_server' key.

- For example, two entries in the list would look like:
        [
            {
                'provider_name': 'Level3',
                'primary_server': '209.244.0.3',
                'secondary_server': '209.244.0.4'
            },
            {
                'provider_name': 'Verisign',
                'primary_server': '64.6.64.6',
                'secondary_server': '64.6.65.6'
            }
        ]
5. Super Bonus: use the pprint module to print the dictionary and list more elegantly. This will take a lot of research, but we will cover this in a future class.

---

## UserAdmin

When you buy a new home WiFi router, it typically comes with one admin login and password to access settings via the product's website. If you don't have this admin password, you're unable to change things like the WiFi network name and password.

In this activity, you'll use Python to build a login system for a WiFi router that only allows those with admin credentials to log in.

### Instructions

1. Open up Unsolved/UserAdmin.py.

2. Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below:

# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]
3. Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin list of logins. The function should set a variable loggedIn to True if the credentials are found in the admin list, and set the variable to False otherwise.

Now that we know how to check to see if a user is logging in with admin credentials, let's set up the part of the system that will continue to prompt the user for their username and password if they didn't enter correct admin credentials before.

4. Create a while loop that will continue to call getCreds and checkLogin until a user logs in with admin credentials.

5. After each call of checkLogin in the while loop, print to the terminal the string "---------".

6. Once the user logs in with admin credentials, print to the terminal the string "YOU HAVE LOGGED IN!".

3. Run the code often as you write and test individual functions with correct and incorrect admin credentials to make sure you're on the right path!

----------------------------------------------------------------------------------------------------------------------

Here is the template I have been given...

providers = ["Level3", "Verisign", "Google", "Quad9", "DNS.WATCH",
             "Comodo Secure DNS", "OpenDNS Home", "Norton ConnectSafe",
             "GreenTeamDNS", "SafeDNS", "OpenNIC", "SmartViper", "Dyn",
             "FreeDNS", "Alternate DNS", "Yandex.DNS", "UncensoredDNS",
             "Hurricane Electric", "puntCAT", "Neustar", "Cloudflare",
             "Fourth Estate"]

ips = ["209.244.0.3", "64.6.64.6", "8.8.8.8", "9.9.9.9", "84.200.69.80",
       "8.26.56.26", "208.67.222.222", "199.85.126.10", "81.218.119.11",
       "195.46.39.39", "69.195.152.204", "208.76.50.50", "216.146.35.35",
       "37.235.1.174", "198.101.242.72", "77.88.8.8", "91.239.100.100",
       "74.82.42.42", "109.69.8.51", "156.154.70.1", "1.1.1.1", "45.77.165.194"]


####################################
### Part 1 - Provider Dictionary ###
####################################
DNS_dictionary = {}

# Use a for loop to create a dictionary mapping the provider names to their IPs. expected output: {'Level3': '209.244.0.3', ...}
<YOUR CODE HERE>

print("DNS Dictionary: ")
print(DNS_dictionary)
print("--------")

# Use the dictionary to print Hurricane Electric's IP
print("Hurricane Electric's IP is: " + <YOUR CODE HERE>)
print("--------")
print("--------")


##################################
### Part 2 - List of Providers ###
##################################
DNS_dictionaries = []

# Use a for loop to create a list of dictionaries with the associated information. expected output: [{'provider_name': 'Level3', 'primary_server': '209.244.0.3'}, ...]
<YOUR CODE HERE>

print("DNS Dictionaries: ")
print(DNS_dictionaries)
print("--------")

# Use the list to print the total number of providers
print("Number of providers: " + <YOUR CODE HERE>)
print("--------")
print("--------")

------------------------------------------------------------------------------------------------------------------

[b][u]Final Resource Provided...[/u][/b]

# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]

# Build your login functions below
----------------------------------------------------------------------------------------------------------------

My Notes

Hello,

I am new to this forum. I am hoping to find some help on my Python Homework. I am currently in a Cyber Security Bootcamp. I did not know it would require so much Python Programming work. We are currently in our final week of the Python section. Unfortunately I have fallen a bit behind as we dived into the more complicated concepts very quickly. Confused

I am not the only one that feels this way. Many are struggling in the class and describe what often happens to me; We just stare blankly at the screen trying to wrap my head around how to even begin. The instructor isn't very clear and sometimes we are expected to research brand new never covered concepts to solve in class exercises. Then the answers are given only for us to find out we had never even taught the concepts. "How can I have known this?" Huh Is something the other noobs in the class ask themselves. Wall

I know I have a lot to catch up on and learn. This is why I will take any advice and help.

Below I will reply with more info on the assignment itself and how I am attempting to solve it.

Thank you everybody.
Ok, when you get stuck, post the specific part your stuck on with code in python code tags and any errors received in error tags.
(Mar-15-2019, 05:19 PM)Yoriz Wrote: [ -> ]Ok, when you get stuck, post the specific part your stuck on with code in python code tags and any errors received in error tags.

Thanks, I will do that as soon as I get the chance. I am currently almost completely lost. Luckily our professor extended the dead line and giving us some coaching after class today. I will come back with more info.
I am also having trouble with this one as well.


# Use a for loop to create a dictionary mapping the provider names to their IPs. expected output: {'Level3': '209.244.0.3', ...}
<YOUR CODE HERE>

print("DNS Dictionary: ")
print(DNS_dictionary)
print("--------")

# Use the dictionary to print Hurricane Electric's IP
print("Hurricane Electric's IP is: " + <YOUR CODE HERE>)
print("--------")
print("--------")

That is the part im confused at. I am assuming I have to create a for loop which I came up with

for providers in range (0,0): but that def does not look right..
Try for provider, ip in zip(providers, ips):
I too have run into a wall with the second part of this assignment.

2. Create a function named getCreds with no parameters that will prompt the user for their username and password. This function should return a dictionary called userInfo that looks like the dictionaries below:
3. Create a function named checkLogin with two parameters: the userInfo and the adminList. The function should check the credentials to see if they are contained within the admin list of logins. The function should set a variable loggedIn to True if the credentials are found in the admin list, and set the variable to False otherwise.

Now that we know how to check to see if a user is logging in with admin credentials, let's set up the part of the system that will continue to prompt the user for their username and password if they didn't enter correct admin credentials before.

4. Create a while loop that will continue to call getCreds and checkLogin until a user logs in with admin credentials.

5. After each call of checkLogin in the while loop, print to the terminal the string "---------".

6. Once the user logs in with admin credentials, print to the terminal the string "YOU HAVE LOGGED IN!".

What I have written so far below:
# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]

# Build your login functions below
# creates a function called getCreds with no paramaters
def getCreds():
    #Prompts user for their username and password
    username = input("What is your username? ")
    password = input("What is your password? ")

    #Dictionary that retains username and password 
    userInfo = [
        {
            "username" : username, 
            "password" : password
        }
    ]
    #Return userInfo
    return userInfo

def checkLogin(userInfo, adminList):
    
    if userInfo in adminList:
        loggedIn = True

    else: 
        loggedIn = False

    while loggedIn == False:
        print("Login Failed. ")
        retry = getCreds()
        return retry

getCreds()

checkLogin()
I am having trouble wrapping up the credential check with a loop, though where I went wrong may even be before this part.

Errors I have received.
Error:
Traceback (most recent call last): File "c:/Users/Owner/Desktop/UserAdmin.py", line 45, in <module> checkLogin() TypeError: checkLogin() missing 2 required positional arguments: 'userInfo' and 'adminList'
getCreds() has been called to get back a dictionary with username and password but it has not been stored in a variable
user_info = getCreds()
then when calling checkLogin() it is expecting to be passed userinfo and adminlist
checkLogin(user_info, adminList)
Thanks Yoriz. I am unable to get the credential check to turn up positive results. It loops through and then ends with "Login failed" even when I enter root, toor which is in adminList.

# Administrator accounts list
adminList = [
    {
        "username": "DaBigBoss",
        "password": "DaBest"
    },
    {
        "username": "root",
        "password": "toor"
    }
]

# Build your login functions below
# creates a function called getCreds with no paramaters
def getCreds():
    #Prompts user for their username and password
    username = input("What is your username? ")
    password = input("What is your password? ")

    #Dictionary that retains username and password 
    userInfo = [
        {
            "username" : str(username), 
            "password" : str(password)
        }
    ]
    #Return userInfo
    return userInfo

user_info = getCreds()

def checkLogin(user_info, adminList):
    
    if user_info in adminList:
        loggedIn = True

    else: 
        loggedIn = False

    while loggedIn == False:
        print("Login Failed. ")
        retry = getCreds()
        return retry

getCreds()

checkLogin(user_info, adminList)
No errors but not doing the loop correctly. Here is the output:
Output:
What is your username? root What is your password? toor What is your username? root What is your password? toor Login Failed. What is your username? root What is your password? toor
Note that the requirements say that getCreds should return a dictionary, but it returns a list. That's the problem.