简体   繁体   English

如何用在Ruby文本文件中写入的每一行上找到的文件内容替换从控制台获取的URL中找到的特定字符串?

[英]How to replace a particular string found in URL taken from console with file content found on each line written in text file in Ruby?

I want to replace fuzz word which has been written in URL taken from console with contents of text file having one string per line. 我想用从每行一个字符串的文本文件内容替换从控制台获取的URL中写的模糊词。 After replacing this fuzz word with file content want to fire http request with this replaced content file and store responses with modified requests in new file. 用文件内容替换此模糊词后,要使用此替换的内容文件触发http请求,并将响应与修改后的请求一起存储在新文件中。

I have written like this but getting error: 我这样写,但出现错误:

fuzz1.rb:16: private method `gsub' called for #<URI::HTTP:0x2969040> (NoMethodError)

Code is here: 代码在这里:

require 'net/http'

puts "Enter Target:\n"
target = URI(gets())
new_reference = target
a1 = target.clone
Net::HTTP.start(target.host, target.port) do |http|
request = Net::HTTP::Get.new target.request_uri
response = http.request request 
puts response.body
end
puts "File contents:\n"
f= File.open("fuzz.txt","r")
while line = f.gets do
    puts "Attack value: #{line}"
    b = a1.gsub('fuzz','#{line}')
    c = b
    Net::HTTP.start(c.host, c.port) do |http|
    request = Net::HTTP::Get.new c.request_uri
    response = http.request request 
    puts response.body
    end
end

No idea why this gsub error is coming and not replacing fuzz word found in URL with file line content. 不知道为什么会出现此gsub错误,而不用文件行内容替换URL中找到的模糊词。

a1 is an URI object, it doesn't have a gsub method. a1是URI对象,它没有gsub方法。 You need to cast it to a string. 您需要将其转换为字符串。 Try this 尝试这个

    b = URI.parse(a1.to_s.gsub('fuzz','#{line}'))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想将每行写的文件内容放置在从Ruby控制台获取的字符串/ URL中定义的特殊符号中 - I want to place file contents written per line with a special symbol defined in string /URL taken from console in Ruby 如果使用Ruby找到字符串,如何从$ stdout中搜索特定字符串并将整个$ stdout存储在文本文件中? - how to search particular string from $stdout and store whole $stdout in text file if string is found using Ruby? Ruby在文本文件中找到一个字符串,然后输出在其上找到的行 - Ruby find a string in a text file and output the line it's found on 找到匹配项后如何替换 ruby 文件中的字符串 - how to replace a string in a ruby file after a match is found 如何在文本文件中搜索字符串,然后打印/返回/输出在Ruby中作为数字找到的文件的哪一行 - How do I search a text file for a string and then print/return/put out what line of the file it was found on as a number in Ruby 在ruby中找到匹配项后寻找替换文件中的文本 - Looking to replace the text in a file after match found in ruby 如何使用Ruby替换文本文件中每个字符的高位? - How to replace high bit for each character in a text file using Ruby? Ruby:如何替换文件中的文本? - Ruby: How to replace text in a file? 如何在Ruby中打印文本文件的每一行? - How do I print each line of a text file in Ruby? 从文本文件中搜索字符串并删除该行RUBY - search a string from a text file and delete that line RUBY
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM