Python Program to Find Subnet Mask

import socket

hostname = socket.gethostname()
IP = socket.gethostfromname(hostname)

if IP.startswith('192.168') == True:
    Subnet_mask = '255.255.0.0'
else:
    Subnet_mask = '255.255.255.0'

def get_ID(ip, mask):
    ip = ip.split('.')
    mask = mask.split('.')
    ip = [int(bin(int(octet)), 2) for octet in ip]
    mask = [int(bin(int(octet)), 2) for octet in mask]
    broadcast = [(ioctet | ~moctet) & 0xff for ioctet, moctet in zip(ip, mask)]
    broadcast = str(broadcast[0]) + '.' + str(broadcast[1]) + '.' + str(broadcast[2]) + '.' + str(broadcast[3])
    return broadcast

broadcastaddr = get_ID(IP, Subnet_mask)