Jump to content

Featured Replies

Posted

Today, I think it will be an easy one. Write a program that validates IPv4 and IPv6 addresses.

Basic Requirements:

  1. Accept a string input from the user.
  2. Check if the input is a valid IPv4 address (e.g., 192.168.1.1).
  3. Check if the input is a valid IPv6 address (e.g., 2001:0db8:85a3:0000:0000:8a2e:0370:7334).
  4. Print whether the address is valid, and if so, specify the type (IPv4 or IPv6).

Bonus Features:

  • Detect private IP ranges for IPv4.
  • Handle CIDR notation (e.g., 192.168.1.0/24).
  • Identify loopback addresses (e.g., 127.0.0.1 for IPv4, ::1 for IPv6).

Example Output:

Enter an IP address: 192.168.1.1
Valid IPv4 address (Private)

Enter an IP address: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Valid IPv6 address

Enter an IP address: 256.256.256.256
Invalid IP address
  • Views 99
  • Created
  • Last Reply

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.