3
2
I can use netcat
to transfer files between two computers.
# Server
nc -l -p 8080 < file
# client
nc 192.168.1.101 8080 > file
Can I use netcat
to download a URL from Internet like wget
?
3
2
I can use netcat
to transfer files between two computers.
# Server
nc -l -p 8080 < file
# client
nc 192.168.1.101 8080 > file
Can I use netcat
to download a URL from Internet like wget
?
7
Assuming you mean a regular HTTP URL, it's possible but it requires you to manually type in the HTTP Request. If the URL requires an HTTP POST with a url-encoded form or looks for specific headers, this can be quite cumbersome.
You will need to supply a valid HTTP Request to the stdin of netcat. The general idea is:
Execute the command nc example.com 80
netcat will start reading from stdin
, and whatever you type in or paste into the terminal will be sent over the network to the remote server on the port you selected (80 is the default HTTP port).
Now you need to type in or paste an HTTP request, like:
GET / HTTP/1.1
Host: example.com
User-Agent: netcat
You'll also need some newlines at the end, so press enter repeatedly until you get the HTTP response back. Then you'll have to manually parse the response.
netcat works at the TCP layer, so any protocol based on HTTP can technically be used with netcat, but for protocols that don't suit to human input (such as ssh and https), it can be difficult to use if you aren't scripting it from a program. And if you ARE writing a program, why aren't you just using normal TCP sockets?
The limitations of netcat for this purpose are as follows:
1
# create a request file
$ cat req
GET / HTTP/1.1
Host: superuser.com
User-Agent: Mozilla/5.0
# send request to get response
$ nc superuser.com 80 <req >res