Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. import os
  2. import struct
  3. def main():
  4. a=os.popen('ip a | grep "scope global"').read()
  5. a=a.split("/")
  6. ip = a[0].split(" ")[5]
  7. masqueRaw = a[1].split(" ")[0]
  8. masque = []
  9. cpt=0
  10. for i in range(4):
  11. temp=""
  12. for j in range(8):
  13. cpt+=1
  14. if cpt<=int(masqueRaw):temp+="1"
  15. else:temp+="0"
  16. masque.append(temp)
  17. ip=ip.split(".")
  18. masque = list(map(lambda x: int(x,2),masque))
  19. network=""
  20. for i in range(4):
  21. temp=int(ip[i]) & masque[i]
  22. network+=str(temp)
  23. if i<4: network+="."
  24. sys.exit(network)
  25. return network
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement