This article mainly introduces how to generate an IP segment in python. it involves skills related to reading and writing Python files and random number operations, and has some reference value, for more information about how to generate IP segments in python, see the following example. Share it with you for your reference. The specific implementation method is as follows:
#! /Usr/local/bin/python #-*-coding: UTF-8 -*-#################################### ########################## generate an IP address segment in python ########## ######################################## ########### if _ name _ = '_ main __': xxx1_file('test.txt ', 'w') for IP1 in range (254,0,-1): for IP2 in range (254,0,-1): # for IP3 in range (254,0,-1): # for IP4 in range (254,0,-1): # print IP1, IP2 abc = '% s. % s. % s-% s. % s. % s \ n' % (IP1, IP2, "1.1", IP1, IP2, "255.255") xxx. write (abc) xxx. close ()
Shows the running effect:
I hope this article will help you with Python programming.