Skip to content

Commit

Permalink
Socat is way better than netcat
Browse files Browse the repository at this point in the history
  • Loading branch information
hunner committed Mar 14, 2016
1 parent 6bf7c37 commit 3ae5e6a
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,7 @@
end
if ! UNSUPPORTED_PLATFORMS.include?(fact('osfamily'))
pp = <<-EOS
$netcat = $::osfamily ? {
'RedHat' => $::operatingsystemmajrelease ? {
'7' => 'nmap-ncat',
default => 'nc',
},
'Debian' => 'netcat-openbsd',
}
package { $netcat: ensure => present, }
package { 'socat': ensure => present, }
package { 'screen': ensure => present, }
if $::osfamily == 'RedHat' {
class { 'epel': }
Expand All @@ -56,7 +49,8 @@ class { 'epel': }
apply_manifest(pp, :catch_failures => true)

['5556','5557'].each do |port|
shell(%{echo 'while :; do echo "HTTP/1.1 200 OK\r\n\r\nResponse on #{port}" | nc -l #{port} ; done' > /root/script-#{port}.sh})
content = "socat -v tcp-l:#{port},reuseaddr,fork system:\"printf \\'HTTP/1.1 200 OK\r\n\r\nResponse on #{port}\\'\",nofork"
create_remote_file(host, "/root/script-#{port}.sh", content)
shell(%{/usr/bin/screen -dmS script-#{port} sh /root/script-#{port}.sh})
sleep 1
shell(%{netstat -tnl|grep ':#{port}'})
Expand Down

0 comments on commit 3ae5e6a

Please sign in to comment.