randomip.py 800 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-"
  3. """
  4. This file is part of the UFONet project, https://ufonet.03c8.net
  5. Copyright (c) 2013/2020 | psy <epsylon@riseup.net>
  6. You should have received a copy of the GNU General Public License along
  7. with UFONet; if not, write to the Free Software Foundation, Inc., 51
  8. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  9. """
  10. from random import randrange
  11. class RandomIP(object):
  12. """
  13. Class to generate random valid IP's
  14. """
  15. def _generateip(self, string):
  16. notvalid = [10, 127, 169, 172, 192]
  17. first = randrange(1, 256)
  18. while first is notvalid:
  19. first = randrange(1, 256)
  20. _ip = ".".join([str(first), str(randrange(1, 256)),
  21. str(randrange(1, 256)), str(randrange(1, 256))])
  22. return _ip