ruby find ip:port regex in html page


SUBMITTED BY: Guest

DATE: Sept. 28, 2014, 8:29 p.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 790

  1. def find_ip(body)
  2. lst_proxy = []
  3. regex_ip_port = '\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?:?[0-9]{0,5})\b'
  4. regex_domain_port = '^[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}:[0-9]{0,5}$'
  5. #res = body.gsub(/<\/?[^>]+>/, '')
  6. doc = Nokogiri::HTML(body)
  7. #doc.xpath("//text()").to_s
  8. res = doc.xpath("//text()").text
  9. #res_strip = res.split(/(\n)+/)
  10. #puts res
  11. res.each do |part|
  12. temp_part = part.split(" ")
  13. temp_part.each do |sub_part|
  14. if sub_part.match(regex_domain_port) && connect_http_mech_anon(sub_part.match(regex_domain_port))
  15. puts sub_part.match(regex_domain_port)
  16. lst_proxy << sub_part.match(regex_domain_port)
  17. elsif sub_part.match(regex_ip_port) && connect_http_mech_anon(sub_part.match(regex_ip_port))
  18. puts sub_part.match(regex_ip_port)
  19. lst_proxy << sub_part.match(regex_ip_port)
  20. end
  21. end
  22. end
  23. return lst_proxy
  24. end

comments powered by Disqus