0

Is it possible to open a socket on a given URL and get its output printed, something similar to curl but for TCP using bash?

Currently I am using a Google Chrome browser extension -> Simple Websocket Client but i would like to make my own scripts and direct the output in my preferred files etc..

Can it be done ?

PS: so far I have also used telnet but I need to pass a path too host:port:path.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Bercovici Adrian
  • 8,794
  • 17
  • 73
  • 152

1 Answers1

1

If you version of bash supports networking

#!/bin/bash
set -u
host="$1"
port="$2"
path="$3"
exec 3<>/dev/tcp/$host/$port
printf '%s\r\n' "$path" >&3
cat <&3

if you are hitting a HTTP server the probably you have to pass the GET requests as path, something like

script example.com 80 $'GET / HTTP/1.1\r\nConnection: close\r\n'
Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134