In bash
, we can use file descriptors in order to (try to) open socket descriptors, as follow:
exec 3<>/dev/prot/host/port
where:
prot
can betcp
orudp
;host
can be a valid hostname or Internet address;port
can be an integer port number or service name.
This is just an example and any redirection can be used
(E.G. printf "%s" "${payload}" >"/dev/udp/${host}/${port}"
).
This is true at least starting from bash v4+
.
Someone else already asked to accomplish the very same thing without a bash built-in;
I already found and tried other solutions, including (but not limited to):
nc
/netcat
/nmap
/tcping
(or similar), in order to "scan" (local or remote) ports (some of those will not be able to receive payloads);netstat
/ss
(or similar), in order to know LISTEN-state (local) ports (and cannot send nor receive any payload);
Among the others, nc
could be considered the most portable solution for this task even though (at least in my understandings) it should not be in coreutils; while solutions as ss
cannot be considered valid for this task because they cannot "scan" another host and cannot send nor receive payloads;
Anyway, it happened to me to find some environment where nc
was not installed.
I can't assume other interpreters are installed (E.G. python
, perl
, etc.);
I can't assume compilers are installed.
Finally, as you already guessed, the question:
There is some posix-way, using anything but a shell, to accomplish a full connection?
In other words, there is a portable way to make use of connections?