Scan gogs Server script (Ruby) in LAN

Source: Internet
Author: User



Scangogs.rb


#! / usr / bin / env ruby
require ‘open-uri’
require ‘thread’
require ‘english’

# configs
CONFIG_IPDOMAIN = ‘30 .93.41. ’
CONFIG_RANGE = (2..254)
CONFIG_URITEMPLATE = ‘http: //% s: 3000 / user / login’

# tty
TTY_FG = {Black: 30, Red: 31, Green: 32, Yellow: 33, Blue: 34,
           Magenta: 35, Cyan: 36, White: 37} .freeze
TTY_BG = {Black: 40, Red: 41, Green: 42, Yellow: 43, Blue: 44,
           Magenta: 45, Cyan: 46, White: 47} .freeze
TTY_MD = {Reset: 0, Bold: 1, Italics: 3, Underlined: 4} .freeze

def tty_msg (msg, tty_fg: nil, tty_bg: nil, tty_md: nil)
  if STDOUT.tty? || STDIN.tty? || STDERR.tty?
    "\ 033 [# {TTY_MD [tty_md]}; # {TTY_FG [tty_fg]}; # {TTY_BG [tty_bg]} m # {msg} \ 033 [0m"
  else
    msg
  end
end

# tty styles
def note_style (msg)
  tty_msg (msg, tty_fg:: Yellow, tty_md:: Underlined)
end

def yes_style (msg)
  tty_msg (msg, tty_fg:: Black, tty_md:: Bold, tty_bg:: Green)
end

def error_style (msg)
  tty_msg (msg, tty_fg:: White, tty_bg:: Red)
end

# main
puts note_style (‘Working ...’)
success_list = []
threads = []
CONFIG_RANGE.each do | n |
  threads << Thread.new do
    s = CONFIG_IPDOMAIN + String (n)
    uri = format (CONFIG_URITEMPLATE, s)
    begin
      open (uri)
      s << yes_style ("\ t ** YES **")
      success_list << uri
    rescue
      s << error_style ("\ terror") << "# {$ ERROR_INFO} \ n"
    end
    puts s
  end
end

threads.each (&: join)
puts note_style (‘Result:‘)
success_list.each {| s | puts s} 




Scan gogs Server script (Ruby) in LAN


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.