/dev/tcp not found

When I try to run the following command:

echo -e "GET / HTTP/1.1nn" | /dev/tcp/74.125.225.19/80

I get the following error message:
bash: /dev/tcp/74.125.225.19/80: No such file or directory

The following command works perfectly, so the problem involves how I’m using /dev/tcp:
echo -e "GET / HTTP/1.1nn" | nc 74.125.225.19 80

I’m in Ubuntu 13.04, so the capability should be on my system. What am I doing wrong? What are the rules for using /dev/tcp properly?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You have to use it in redirections:

Bash handles several filenames specially when they are used in
redirections, as described in the following table:

/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 the
corresponding TCP socket.

So:

printf "GET / HTTP/1.1nn" > /dev/tcp/74.125.225.19/80

is the right way to use it.

When you used /dev/tcp/74.125.225.19/80 in a pipe, bash attempted to run a command named /dev/tcp/74.125.225.19/80 and reported an error because that file didn’t exist.


The ability to handle /dev/tcp/host/port and /dev/udp/host/port in redirection was added to bash in version 2.04.

You need to compiled bash with --enable-net-redirections option.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments