# !/usr/bin/python3
# coding: utf-8
import IPy
def in_same_segment(ip, mask, addr):
"""
ip like 127.0.0.1
mask like 255.0.0.0
addr like 192.168.1.1
"""
# Specifies whether the address is in the network segment
if '' == addr.strip():
return True
subnet = IPy.IP('%s/%s' % (ip, mask), make_net=True)
if addr not in subnet:
print('Address %s is not in the segment of %s' % (addr, subnet))
return False
return True