LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2014, 10:48 AM   #1
czezz
Member
 
Registered: Nov 2004
Distribution: Slackware/Solaris
Posts: 924

Rep: Reputation: 43
bash and /dev/tcp - how does that work ?


Can anyone explain me how following works ?
This command checks if eg. remote host 10.2.12.25 or 10.2.12.26 has a daemon listening on port 22 / or port 22 is open. If it's TRUE, returns value 0, if not 1.
Very useful for me. The only question is how does that work ?
I checked in my system - /dev/tcp does not exist... so how is that possible it works ?

Code:
# bash -c 'exec 3<> /dev/tcp/'10.2.12.25'/'22';echo $?' 2>/dev/null
0
# bash -c 'exec 3<> /dev/tcp/'10.2.12.26'/'22';echo $?' 2>/dev/null
1

Last edited by czezz; 05-13-2014 at 11:39 AM.
 
Old 05-13-2014, 12:30 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,863
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Bash has a built-in tcp-client functionality -- this '/dev/tcp/ip/port' is handled by bash, the kernel never sees it.
 
1 members found this post helpful.
Old 05-14-2014, 03:01 AM   #3
gnashley
Amigo developer
 
Registered: Dec 2003
Location: Germany
Distribution: Slackware
Posts: 4,928

Rep: Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612Reputation: 612
Somewhere around here I have bash-only implementation of wget which uses the bash tcp functionality to mimic wget.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
/dev/tcp not there in LINUX smilebhuff Programming 2 05-17-2012 04:40 AM
[SOLVED] Bash script to try to mount evreything in the dev directory does not work smeezekitty Programming 3 12-23-2009 12:07 AM
BASH script: can't get a {cat > /dev/...} to work in background 2lunious Programming 16 10-03-2009 06:22 AM
not work: iptables -I INPUT 5 -m state --state NEW -m tcp -p tcp --dport 3306 -j DROP abefroman Linux - Security 1 07-18-2007 08:19 AM
bash: using /dev/tcp to connect to an smtp server: issues techguy Programming 4 09-20-2006 11:56 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration