randomip.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. # vim: set expandtab tabstop=4 shiftwidth=4:
  4. """
  5. $Id$
  6. This file is part of the xsser project, http://xsser.03c8.net
  7. Copyright (c) 2011/2016 psy <epsylon@riseup.net>
  8. xsser is free software; you can redistribute it and/or modify it under
  9. the terms of the GNU General Public License as published by the Free
  10. Software Foundation version 3 of the License.
  11. xsser is distributed in the hope that it will be useful, but WITHOUT ANY
  12. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  14. details.
  15. You should have received a copy of the GNU General Public License along
  16. with xsser; if not, write to the Free Software Foundation, Inc., 51
  17. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. """
  19. from random import randrange
  20. class RandomIP(object):
  21. """
  22. Class to generate random valid IP's
  23. """
  24. def _generateip(self, string):
  25. notvalid = [10, 127, 169, 172, 192]
  26. first = randrange(1, 256)
  27. while first is notvalid:
  28. first = randrange(1, 256)
  29. _ip = ".".join([str(first), str(randrange(1, 256)),
  30. str(randrange(1, 256)), str(randrange(1, 256))])
  31. return _ip
  32. if __name__ == "__main__":
  33. randomip = RandomIP()
  34. print randomip._generateip('')