PYTHON_JOB_INTERVIEW Telegram 1237
🔥 Полезный Python-трюк для работы с сетями: `ipaddress` в стандартной библиотеке

Когда нужно быстро проверить IP-адреса, маски подсетей или принадлежность хоста сети — не обязательно тянуть внешние пакеты. В Python уже есть мощный модуль ipaddress.


import ipaddress

# Создаём сеть
net = ipaddress.ip_network("192.168.1.0/24")

# Проверяем, входит ли IP в сеть
print(ipaddress.ip_address("192.168.1.42") in net) # True
print(ipaddress.ip_address("10.0.0.5") in net) # False

# Перебираем все адреса подсети
for ip in net.hosts():
print(ip)
break # выведет первый адрес

# Работаем с IPv6 так же просто
ipv6 = ipaddress.ip_network("2001:db8::/32")
print(ipaddress.ip_address("2001:db8::1") in ipv6) # True


📌 Чем полезно

Проверка принадлежности адреса подсети

Удобный парсинг IPv4 и IPv6

Генерация диапазонов IP

Всё встроено в Python — никаких сторонних зависимостей

🔥 Отлично подходит для написания сетевых тулзов, firewall-скриптов, DevOps-автоматизации и тестов.

#Python #Networking #Tips #DevOps
👍84



tgoop.com/python_job_interview/1237
Create:
Last Update:

🔥 Полезный Python-трюк для работы с сетями: `ipaddress` в стандартной библиотеке

Когда нужно быстро проверить IP-адреса, маски подсетей или принадлежность хоста сети — не обязательно тянуть внешние пакеты. В Python уже есть мощный модуль ipaddress.


import ipaddress

# Создаём сеть
net = ipaddress.ip_network("192.168.1.0/24")

# Проверяем, входит ли IP в сеть
print(ipaddress.ip_address("192.168.1.42") in net) # True
print(ipaddress.ip_address("10.0.0.5") in net) # False

# Перебираем все адреса подсети
for ip in net.hosts():
print(ip)
break # выведет первый адрес

# Работаем с IPv6 так же просто
ipv6 = ipaddress.ip_network("2001:db8::/32")
print(ipaddress.ip_address("2001:db8::1") in ipv6) # True


📌 Чем полезно

Проверка принадлежности адреса подсети

Удобный парсинг IPv4 и IPv6

Генерация диапазонов IP

Всё встроено в Python — никаких сторонних зависимостей

🔥 Отлично подходит для написания сетевых тулзов, firewall-скриптов, DevOps-автоматизации и тестов.

#Python #Networking #Tips #DevOps

BY Python вопросы с собеседований


Share with your friend now:
tgoop.com/python_job_interview/1237

View MORE
Open in Telegram


Telegram News

Date: |

Hui said the messages, which included urging the disruption of airport operations, were attempts to incite followers to make use of poisonous, corrosive or flammable substances to vandalize police vehicles, and also called on others to make weapons to harm police. As the broader market downturn continues, yelling online has become the crypto trader’s latest coping mechanism after the rise of Goblintown Ethereum NFTs at the end of May and beginning of June, where holders made incoherent groaning sounds and role-played as urine-loving goblin creatures in late-night Twitter Spaces. Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020. Although some crypto traders have moved toward screaming as a coping mechanism, several mental health experts call this therapy a pseudoscience. The crypto community finds its way to engage in one or the other way and share its feelings with other fellow members. Each account can create up to 10 public channels
from us


Telegram Python вопросы с собеседований
FROM American