socat error - unknown option "proxyport:8080" - proxy

I'm trying to run a simple forwarding proxy through another proxy server.
But as soon as I connect to the opened port (e.g. curl localhost:9090) an error is thrown and the connection is closed.
$ socat -v TCP-LISTEN:9090,fork PROXY:proxyhost:google.com:80,proxyport:8080
2020/03/01 15:00:00 socat[109218] E parseopts(): unknown option "proxyport:8080"
I'm using socat version 1.7.3.2 on May 11 2017 13:28:30
with features -> #define WITH_PROXY 1
I tried this on Suse as well as alpine linux and get the same result.
Am I doing something wrong or is this a bug?
Thanks in advance

I wrote to the mailing list and the maintainer made me aware of my mistake.
The parameter value must be seperated by an equals instead of a colon.
$ socat -v TCP-LISTEN:9090,fork PROXY:proxyhost:google.com:80,proxyport=8080

Related

curl command not working on M1 bash command line

currently busy learning kubernetes and running configs on the command line, and I'm using an M1 MacOS running on version 11.5.1, and one of the commands I wanted to run is curl "http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy" but I get the below error message curl: (3) URL using bad/illegal format or missing URL. Not sure if anyone has experienced this issue before, would appreciate the help.
First, curl command should receive only 1 host, not multiple hosts.
Therefore pod should be single.
Then, you need to save POD's name to a variable without any special characters.
Last, when you're using kubectl proxy, you need to add -L option to the curl command so it will follow the redirection.
Simple example will be:
# run pod with echo image
kubectl run echo --image=mendhak/http-https-echo
# start proxy
kubectl proxy
# export pod's name
export POD_NAME=echo
# curl with `-I` - headers and `-L` - follow redirects
curl -IL http://localhost:8001/api/v1/namespaces/default/pods/$POD_NAME/proxy
HTTP/1.1 301 Moved Permanently
Location: /api/v1/namespaces/default/pods/echo/proxy/
HTTP/1.1 200 OK
The problem is that POD_NAME contains two pods separated by space. Therefore the url that you are trying to refer is
malformed - because of space in it - and that's the reason for the error message
wrong - you need to put name of the pod you want to access in there, not both at once

How to send the data to TCP PORT using shell script commands

I’m looking for a solution to send the data from a file to the TCP port which is available on the specific server using the shell script/Unix command.
When I checking for this option I found the below one but it’s not working out? Is there any solution is available?
The command I tried from a shell script and find the response below.
Option 1: exec cat /home/data/load.txt > /dev/tcp/$host/$port
-bash: : Name or service not known
-bash: /dev/tcp//: Invalid argument
Option 2:
ncat -v -w 2 hostname 4053 < /home/data/test.txt
Ncat: Version 7.50 ( https://nmap.org/ncat )
Ncat: Connected to xx.xx.xx.xx:4053.
Ncat: Connection reset by peer.
It would be helpful if could someone help with this.
Thanks | SP

How can I get telnet to work successfully in Gitbash?

I am trying to run telnet in gitbash on windows, but when I enter the command telnet, I just get returned to my command line. I already enabled the telnet client like the link at the bottom of this question explained.
The problem now is that when I type telnet into gitbash, nothing happens, and I am just returned a new command line. If I open up a windows shell and type telnet then it runs as expected, which leads me to believe it's an issue with gitbash.
How can I get telnet to work successfully in Gitbash?
Link to a similar question, but only explains how to enable the tcp client, not how to get gitbash to run it: Can not use command telnet in git bash
I don't think that git-bash is meant to run such programs. It may be possible to do so, but it only contains minimal utilies, often useful to manage your repositories.
If you want extended unix-system on windows, use a VM or Windows Subsystem for Linux (often called bash on windows).
If you just want to run the windows telnet program from git bash, you can simply write the path to it, eg C:/Users/Documents/telnet/telnet.exe
Just to complement #NanoPish's answer, telnet need to be invoked with winpty(for those who used MinTTY as terminal emulator) on git bash to work.
Example:
MINGW64 ~
$ which telnet
/c/WINDOWS/system32/telnet
MINGW64 ~
$ winpty telnet localhost 2181
Zookeeper version: 3.4.14-4c25d480e66aadd371de8bd2fd8da255ac140bcf, built on 03/06/2019 16:18 GMT

socat fake http server - use a file as server response

I've been trying to use socat to respond on each connection to a socket it's listening to with a fake HTTP reply. I cannot get it working. It might be because I'm using the cygwin version of socat? I don't know.
Part of the problem is I want the second argument <some_file_response> not to be written to. In other words because it's bidirectional it will read what's in response.txt and then write to that same file, and I don't want that. Even if I do open:response.txt,rdonly it doesn't work repeatedly. system: doesn't seem to do anything. exec seems like it works, for example I can do exec:'cat response.txt' but that never gets sent to the client connecting to port 1234.
socat -vv tcp-listen:1234,reuseaddr,fork <some_file_response>
I want it to read a file to the client that's connected and then close the connection, and do that over and over again (that's why I used fork).
I am putting a bounty on this question. Please only give me solutions that work with the cygwin version from the windows command prompt.
Tested with cygwin:
socat -vv TCP-LISTEN:1234,crlf,reuseaddr,fork SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo; cat <some_file_response>"
If you do not want a complete HTTP response, leave out the echos:
socat -vv TCP-LISTEN:1234,crlf,reuseaddr,fork SYSTEM:"cat <some_file_response>"
Taken from socat examples
socat -vv TCP-LISTEN:8000,crlf,reuseaddr,fork SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo; cat"
This one works:
socat -v -v -d -d TCP-LISTEN:8080,reuseaddr,fork exec:"cat http.response",pipes
Two things need to be aware,
should you add crlf, as in other answers. I recommend not.
crlf caused problem sending image
just use \r\n explicitly in http response headers.
without pipes, seems no data sent to client. browser complains:
127.0.0.1 didn’t send any data.
ERR_EMPTY_RESPONSE
tested in cygwin.
== EDIT ==
If you want use inside cmd.exe, make sure PATH is correctly set, so that socat and cat can be found.
Say both socat.exe and cat.exe located under E:\cygwin64\bin
set PATH=%PATH%;E:\cygwin64\bin
Works in cmd.exe, with socat & cat from cygwin.

When starting WEBrick/Jekyll it produces a TCPServer Error (Address already in use)

I'm trying to start my local Jekyll server but it just won't work and no matter which port I choose it always comes down to the error:
WARN TCPServer Error: Address already in use - bind (2)
I tried to follow some instructions online, which mostly assumed a specific port was already in use, but this doesn't seem to be the case here, since absolutely no port works and commands such as "lsof | grep 4000", etc. produces nothing.
Jekyll version: 0.11.2
Ruby: 1.9.2.-p290
Try
netstat -a -n -p | grep LIST
and search for you port number ( 4000 )
then kill it - the pid should be the last column
If there is no pid at the end then execute the command as root or make a sudo.

Resources