stdin 및 stdout을 포트로 리디렉션 같은. # The

나는 프로그램 싶네요 Pstdin&에 쓰기를 stdout, 그러나에 연결 nc이 다른 포트로 특정 포트와 출력에서 읽이든 같은.

# The reading is easy, here P reads from port 50505
nc -l 50505 | P

포트 60606으로 다시 쓰려면 어떻게해야합니까?



답변

나는 누군가가 당신의 컴퓨터에 2 개의 TCP 연결을 열 수 있고, 하나는 포트 50505에, 다른 하나는 포트 60606에 연결하고, 첫 번째 포트에 데이터를 보내 P로 공급되고 두 번째 TCP 연결에서 P의 출력을 읽을 것으로 예상합니다. 그때는 다음과 같습니다.

< /dev/null nc -q -1 -l 50505 | P | nc -l 60606 > /dev/null

또는과 socat:

socat -u tcp-listen:50505,reuseaddr - | P | socat -u - tcp-listen:60606,reuseaddr

들어 P동일한 연결에 그 출력 등을 보내 :

socat tcp-listen:50505,reuseaddr exec:P


답변

nc포트를 사용하기 위해 필요하지 않습니다 . bash그 자체를 할 수 있습니다 :

Bash는 다음 표에 설명 된 것처럼 리디렉션에 사용될 때 여러 파일 이름을 특별히 처리합니다.

/dev/fd/fd
    If fd is a valid integer, file descriptor fd is duplicated.
/dev/stdin
    File descriptor 0 is duplicated.
/dev/stdout
    File descriptor 1 is duplicated.
/dev/stderr
    File descriptor 2 is duplicated.
/dev/tcp/host/port
   If host is a valid hostname or Internet address, and port is an integer
   port number or service name, bash attempts to open a TCP connection to
   the corresponding socket.
/dev/udp/host/port
    If host is a valid hostname or Internet address, and port is an integer
    port number or service name, bash attempts to open a UDP connection to
    the corresponding socket.


답변