randomip.py 1.3 KB

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