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 184
  • Created
  • Last Reply

Create an account or sign in to comment

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.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.