2022-09-07 13:11:31 +03:00

26 lines
1.1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import ipaddress
def main(ip):
list_ip = ip.split('/') # Разделяет вводимый ip на часть с маской, и без
ipv4 = ipaddress.ip_address(list_ip[0])
print('Ваш ip адрес:', ip) # Выводит например "Ваш ip адрес: 192.168.10.128/24"
net = ipaddress.ip_network(ip, strict=False) # В функцию кладётся сетевая часть ip, без хостовой части
print('Маска:', net.netmask, '=', list_ip[1], '\n') # Выводит маску
print('Network:', net) # Выводит сеть
print('Broadcast:', net.broadcast_address) # Выводит broad
print('HostMin:', net[1])
print('HostMax:', net[-2])
print('Hosts:', len(list(net.hosts()))) # Выводит кол-во хостовых ip
for n_ip in net.hosts():
if str(n_ip) == list_ip[0]:
list_n_ip = str(n_ip).split('.')
print('№ в сети:', list_n_ip[3])
break
if __name__ == '__main__':
addr = input('Введите ip: ') # Пользователь вводит ip
main(addr)