"John S" <lists / netrogenic.com> writes:

> How do i do it in Ruby?
> Now i am using "host" command but that is not optimal.
> 
> def getMX(host) 
>   srand()
>   e_mx = `host -t mx #{host}` # Should be done internally, but HOW?
>   mxhosts = []
>   i = 0
>   e_mx.each do |line|
>     s = line.split(/by /)
>     mxhosts[i] = s[1]
>     i+=1
>   end
>   return mxhosts[rand(mxhosts.length)].chop
> end

You can use the 'resolv.rb' library that comes with Ruby:

    res = Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::MX)


Cheers


Dave