alternative for netcat utility

2020-07-07 16:10发布

Is there any alternative for netcat utility? I want to run docker API and netcat utility is not installed on client system. docker command example - echo -e "GET /info HTTP/1.0\r\n" | nc -U /var/run/docker.sock

标签: linux docker
4条回答
Rolldiameter
2楼-- · 2020-07-07 16:20

Have you got Perl? You could do something like this maybe:

perl -MLWP::Simple -e "getprint('http://localhost')"
查看更多
甜甜的少女心
3楼-- · 2020-07-07 16:34

Python is ubiquitous these days and the socket module is all you need.

Here are a few examples: You can use it to test connectivity on port 443 to a list of 3 hosts:

import socket

def test_socket(ip,port):
        s = socket.socket()

        try:
            s.settimeout(3)
            s.connect((ip,port))
        except socket.error as msg:
            s.close()
            print 'could not open %s:%s %s' % (ip,port,msg)
            return(1)
        else:
            s.close()
            print '%s:%s is OK' % (ip,port)
            return(0)


hosts=['host1.example.com','host2.example.com','host3.example.com']

for host in hosts:
   print "testing %s 443" % host
   test_socket(host,443)

This one liner can read stdin or files and send to hostname termbin.com on port 9999 upload a file to termbin:

 python -c "import socket,fileinput;  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM); s.connect(('termbin.com', 9999)) ; [ s.send(b) for b in fileinput.input() ]; print s.recv(1024); s.close();" filetoupload.txt
查看更多
Evening l夕情丶
4楼-- · 2020-07-07 16:41

According to this,

(exec 3<>/dev/tcp/url/port; cat >&3; cat <&3; exec 3<&-)

can replace nc/netcat. It should work in any bash based terminal.

Example:

printf "Hello World!" | (exec 3<>/dev/tcp/termbin.com/9999; cat >&3; cat <&3; exec 3<&-)

returns a link.

查看更多
倾城 Initia
5楼-- · 2020-07-07 16:42

socat is a more powerful version of nc and netcat.

查看更多
登录 后发表回答