Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import struct
- def main():
- a=os.popen('ip a | grep "scope global"').read()
- a=a.split("/")
- ip = a[0].split(" ")[5]
- masqueRaw = a[1].split(" ")[0]
- masque = []
- cpt=0
- for i in range(4):
- temp=""
- for j in range(8):
- cpt+=1
- if cpt<=int(masqueRaw):temp+="1"
- else:temp+="0"
- masque.append(temp)
- ip=ip.split(".")
- masque = list(map(lambda x: int(x,2),masque))
- network=""
- for i in range(4):
- temp=int(ip[i]) & masque[i]
- network+=str(temp)
- if i<4: network+="."
- sys.exit(network)
- return network
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement