如何用ruby写1000个ip地址?

Python011

如何用ruby写1000个ip地址?,第1张

ruby的ipaddr可以很容易的将ip地址转换成整数,也可以很容易将整数转换成ip地址

require 'ipaddr'

#假设

= IPAddr.new "10.0.2.15"ip.to_i

puts "hello 是写在rb文件中的

eg

app/controllers/hello_controller.rb #画面的控制

class HelloController <ActionController

def index

@hello = "hello"

puts @hello # "hello"

end

end

app/views/hello/index.rhtml

<table border="1">

<tr>

<td><%=@hello%></td> #@hello 或者$hello 这种变量才能在页面中使用

</tr>

</table>

地址是:http://localhost:3000/hello/say