Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- # Filename: is_valid_ip.py
- # Author: Jeoi Reqi
- """
- Valid IP Checker Script
- This script prompts the user to enter an IP address and checks whether
- it is in a valid IP format (IPv4 or IPv6). It utilizes a function, valid_ip,
- to perform the IP validation.
- Requirements:
- - Python 3
- Usage:
- 1. Run the script.
- 2. Enter an IP address when prompted.
- 3. The script will display whether the entered IP address is valid or not.
- """
- import ipaddress
- def valid_ip(ip):
- """Check if IP address is valid.
- Args:
- ip (str): IPv4 or IPv6.
- Returns:
- bool: True if in valid IP format (IPv4/IPv6), False otherwise.
- """
- try:
- ipaddress.ip_address(ip)
- return True
- except Exception:
- return False
- def main():
- # Get user input for IP address
- user_ip = input("Enter an IP address: ")
- # Check if the IP address is valid
- if valid_ip(user_ip):
- print("The entered IP address is Valid.")
- else:
- print("The entered IP address is Not Valid.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement