Ruby - See if a port is open

后端 未结 7 2077
灰色年华
灰色年华 2020-12-04 14:05

I need a quick way to find out if a given port is open with Ruby. I currently am fiddling around with this:

require \'socket\'

def is_port_open?(ip, port)
          


        
7条回答
  •  不知归路
    2020-12-04 15:05

    I recently came up with this solution, making use of the unix lsof command:

    def port_open?(port)
      !system("lsof -i:#{port}", out: '/dev/null')
    end
    

提交回复
热议问题