Last active
November 15, 2022 22:23
-
-
Save brootware/e92597b43247b3b784ef5588265b0ae9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import sys | |
import ipaddress | |
import subprocess | |
banner = r""" | |
__ __.__ _________ .__ .___ | |
/ \ / \__| ____ \_ ___ \|__| __| _/______ | |
\ \/\/ / |/ \ / \ \/| |/ __ |\_ __ \ | |
\ /| | | \ \ \___| / /_/ | | | \/ | |
\__/\ / |__|___| / \______ /__\____ | |__| | |
\/ \/ \/ \/ | |
+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+-+ | |
|P|o|w|e|r|e|d| |b|y| |B|r|o|o|t|w|a|r|e| | |
+-+-+-+-+-+-+-+ +-+-+ +-+-+-+-+-+-+-+-+-+ | |
https://github.com/brootware | |
https://brootware.github.io | |
""" | |
help_menu = """ | |
getcidr - A python script to calculate which cidr subnet range you are on by supplying subnet mask. | |
Example usage:\n | |
python getcidr.py 255.255.248.0 | |
""" | |
def get_current_ip(): | |
return socket.gethostbyname(socket.gethostname()) | |
def calculate_cidr(netmask: str) -> ipaddress.IPv4Network: | |
current_ipaddr = get_current_ip() | |
cidr = ipaddress.ip_network(f'{current_ipaddr}/{netmask}', strict=False) | |
return cidr | |
def get_broadcast(cidr: ipaddress.IPv4Network) -> str: | |
ipi = ipaddress.ip_interface(cidr) | |
return ipi.network.broadcast_address | |
def main(): | |
print(banner) | |
if len(sys.argv) == 1: | |
print(help_menu) | |
sys.exit("[-] Supply your subnet mask. Check from ipconfig /all or ifconfig") | |
subnet_mask = sys.argv[1] | |
cidr = calculate_cidr(subnet_mask) | |
broadcast = get_broadcast(cidr) | |
print(f"[+] CIDR address : {cidr}") | |
print(f"[+] Broadcast address : {broadcast}") | |
if __name__ == "__main__": | |
main() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
def run(cmd): | |
completed = subprocess.run(["powershell", "-Command", cmd], capture_output=True, text=True) | |
return completed | |
if __name__ == '__main__': | |
output = run('ipconfig /all') | |
print(output.stdout) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment