jeudi 28 janvier 2021

Assigninga function to an IF statement

It's been a while since I used python (been studying CISCO IOS) so I'm bit rusty. I have forgotten how to assign a function to an IF statement.

import ipaddress

q1= input("Please enter 'network' to calculate an IP address range, or enter 'port' to scan an ip address for open ports  ")
if (q1 == str(network)):
    networkclac()
if (q1 == str(port)):
    portscan()


def networkclac():
    try:
        network = input('please input network address: ')
        network = ipaddress.ip_network(network)
        print(network)

    except ValueError:
        print('That is not a network address')

    iplist= list(ipaddress.ip_network(network).hosts())
    for i in range(10,len(iplist),2):
        print(iplist[i])

#def portscan():

Output

Traceback (most recent call last):
  File "C:\Users\shane\PycharmProjects\RodCertIV\ITCNWK409.py", line 4, in <module>
    if (q1 == str(network)):
NameError: name 'network' is not defined

Process finished with exit code 1

The aim of the program is to calculate a range of IP addresses, and scan ip addresses for open ports.

I have created the code for the IP Calculator, but I have forgotten how to call up a function in an IF statement.

I want the program, to ask the user if they wish to calculate an IP network address or run a port scan. If the end user inputs "network" I want the program to run the def network clac(): function

It's something quite simple that I'm missing, this should be an easy question for some.

Aucun commentaire:

Enregistrer un commentaire