Monday, March 24, 2014

Reverse Dns check

172:rp young$ cat iptodns.rb 
#!/usr/bin/env ruby
require 'resolv'

def check
 if ARGV[0] == nil
   abort 'Please input ARGV[0]'
 end
end

check

def ipdcheck
 begin 
   puts Resolv.getname(ARGV[0])
 rescue
   puts "No hostname associated with #{ARGV[0]}"
 end
end


ipdcheck


Example)
172:rp young$ ruby iptodns.rb 202.131.30.12
No hostname associated with 202.131.30.12
172:rp young$ ruby iptodns.rb 127.0.0.1
localhost
172:rp young$ ruby iptodns.rb 192.0.34.166
34-166.lax.icann.org
172:rp young$ 

Simple ips to certain dns

172:rp young$ cat dns_ip.rb 
#!/usr/bin/env ruby
def check
 if ARGV[0] == nil
  abort 'please input ARGV[0]'
 end
end

check

require 'resolv'

def check_address
    Resolv.each_address(ARGV[0]) do |ip|
      puts ip
    end
end

check_address
172:rp young$ ruby dns_ip.rb naver.com
125.209.222.142
202.131.30.11
202.131.30.12
125.209.222.141
172:rp young$ 


Port check script by ruby

172:rp young$ cat port_check.rb 
#!/usr/bin/env ruby

require 'rubygems'
require 'net/ping'

if Net::Ping::TCP.new(ARGV[0],ARGV[1]).ping
   puts "Pong!"
else
   puts "No response"
end
172:rp young$ ruby port_check.rb www.google.com 80
Pong!

172:rp young$ 

Ping script with ruby

172:rp young$ cat ping.rb 
require 'rubygems'
require 'net/ping'
if Net::Ping::External.new(ARGV[0]).ping
   puts "Pong!"
else
   puts "No response"

end

172:rp young$ ruby ping.rb www.google.com
Pong!
172:rp young$ 

Monday, March 3, 2014

Simple DNS mx check

#!/usr/bin/env ruby
def check
 if ARGV[0] == nil
 abort 'plz input domain name'
 end
end

check

require 'resolv'
dns = Resolv::DNS.new
domain = ARGV[0]
dns.each_resource(domain, Resolv::DNS::Resource::IN::MX) do |mail_server|
 puts mail_server.exchange

end

#How to test
y-MacBook-Pro:rp young$ ruby mf.rb  
plz input domain name
y-MacBook-Pro:rp young$ ruby mf.rb yahoo.com
mta7.am0.yahoodns.net
mta5.am0.yahoodns.net
mta6.am0.yahoodns.net
y-MacBook-Pro:rp young$ ruby mf.rb nate.com
mx1.nate.com

uploading ftp files

#!/usr/bin/env ruby
#Very simple ftp upload program by ruby
if ARGV[0] == nil
 abort "\nInput ftp site ip or domain name"
elsif ARGV[1] == nil
 abort "\nInput the text file that you want to upload"
end

require 'net/ftp'
ftp = Net::FTP.new(ARGV[0])
ftp.passive = true
ftp.login 'yourname', 'yourpasswd'
ftp.chdir('/dir/to/you/want')
ftp.puttextfile(ARGV[1])
#ftp.putbinaryfile(ARGV[1])
ftp.list('*') { |file| puts file }

ftp.close