Guest User

Untitled

a guest
May 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #!/usr/bin/python
  2. import re
  3. def getIP():
  4. ip = re.compile('d+|\.')
  5. out = []
  6. with open("./ipaddr","r") as f:
  7. while True:
  8. c = f.read(1)
  9. if not c:
  10. break
  11. if ip.match(c):
  12. out.append(c)
  13. for i in range(14):
  14. c = f.read(1)
  15. if ip.match(c):
  16. out.append(c)
  17. else:
  18. if out:
  19. yield "".join(out)
  20. out = []
  21.  
  22. print str([ipad for ipad in getIP()])
  23.  
  24. import re
  25. from functools import partial
  26.  
  27. def getIP(file_name):
  28. ip_regex = re.compile("(?:d{1,3}.){3}d{1,3}")
  29. current = ""
  30. with open(file_name) as file:
  31. for c in iter(partial(file.read, 1), ""):
  32. current += c
  33. current = current[-15:]
  34. m = ip_regex.match(current)
  35. if m:
  36. yield m.group()
  37. current = current[m.endpos:]
Add Comment
Please, Sign In to add comment