Python Forum
IP Subnet is asked from user
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IP Subnet is asked from user
#1
Hi,

I am trying to force the user enter IP format with below code. However, it does not work. User should be enter x.x.x.x/y format for IP to continue.
What is problem on below code?
thanks

def test():
    while True:
        val = raw_input("enter IP:")
        try:
             IP=ipaddress.ip_network(str(val),True)
        except:
            if val == "":
                print " Enter subnet:"
            else:
                print " IP should be formatted X.X.X.X/Y"

test()
Reply
#2
One question, why are you using python 2.7?
Current version is 3.7.2 and 2.7 dies in less than 10 months.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  What is a circular import? asked by a newbie of newbies ineuw 1 926 Sep-16-2022, 07:27 PM
Last Post: Gribouillis
  Subnet Mask Ranges ab52 0 1,785 Mar-11-2019, 10:39 AM
Last Post: ab52

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020