# arirang script examples
# arirang -R multiport.rb -p 22,80,8080 -h yourhost/24 -P 80
class Arirang

#@ari_recvsize = 1024
#@ari_recvflag = 3

     def baedal
        $ari_info = {
        'description' => 'arirang script examples - multi-port',
        'author' => 'pilot pilot@monkey.org'
        }
        puts $ari_info['description'] + "\n\n" 
     end

     def asadal
#do not use such as print, printf, puts, p in asadal
#use the ariprint function.
         ariconnect
         ssh = "arirang"
         http = "GET / HTTP/1.0\r\n\r\n"

         if ($ari_sport == "80" or $ari_sport == "8080")
         httpresp = arisend(http)
         httpresp.each_line do |line|
         x = line.match(/^Server\: (.+)\r/)
            if x != nil
                y = "#{$ari_host} - #{$ari_sport}/tcp - #{x[1]}\n"
                ariprint(y)
            end
           end
         end

         if ($ari_sport == "22")
         sshresp = arisend(ssh)
         sshresp.each_line do |line|
         a = line.match(/^SSH-(.+)/)
            if a != nil
                b = "#{$ari_host} - #{$ari_sport}/tcp - #{a[1]}\n"
                ariprint(b)
            end
           end
         end

        ariclose
     end
end

