Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import subprocess
- import re
- # Define the command to run
- command = "ipconfig /all"
- # Run the command using subprocess
- result = subprocess.run(command, capture_output=True, text=True, shell=True)
- # Check if the command executed successfully
- if result.returncode == 0:
- print("Command executed successfully:")
- output = result.stdout
- # Extract IPv4 addresses using regular expressions
- ip_pattern = re.compile(
- r'IPv4 Address[ .]+: (?P<ip_address>[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)')
- ip_addresses = ip_pattern.findall(output)
- if ip_addresses:
- print("IPv4 Addresses:")
- for ip_address in ip_addresses:
- print(ip_address)
- else:
- print("No IPv4 addresses found.")
- else:
- print("Command execution failed:")
- print(result.stderr)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement