Introduction to how to simply implement subnet mask conversion in Python

高洛峰
Release: 2017-03-06 14:05:04
Original
2023 people have browsed it

The example in this article describes how to simply implement subnet mask conversion in Python. Share it with everyone for your reference, the details are as follows:

Here, the subnet mask length is converted into a specific subnet mask address:

def exchange_maskint(mask_int): bin_arr = ['0' for i in range(32)] for i in range(mask_int): bin_arr[i] = '1' tmpmask = [''.join(bin_arr[i * 8:i * 8 + 8]) for i in range(4)] tmpmask = [str(int(tmpstr, 2)) for tmpstr in tmpmask] return '.'.join(tmpmask) if __name__ == '__main__': print exchange_maskint(24)
Copy after login

For more related articles on how to simply implement subnet mask conversion in Python, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!