From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([69.77.167.62] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1LNhe9-0003YD-HX for garchives@archives.gentoo.org; Fri, 16 Jan 2009 05:53:34 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DCE69E0568; Fri, 16 Jan 2009 05:53:19 +0000 (UTC) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.153]) by pigeon.gentoo.org (Postfix) with ESMTP id 3D387E0568 for ; Fri, 16 Jan 2009 05:53:18 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id e21so716504fga.14 for ; Thu, 15 Jan 2009 21:53:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type:content-transfer-encoding; bh=6BekiN3+bW6JUl3hvHJE66kl+Hp7wwaHwfvSbK1jKLA=; b=Xag9tWY3MSBhWX0P8xV9D/EfvQATX1HMauk9Q+VtL6Bs2YE5Qq67JiUZ7BQEQSvXnt UcgEpjhBPdMzokDJtX1yE1rAq9WCrxnV+/7B4ErjGIKE/mMocF0/88JxeXaHk5Ym7Uue x6tuWoqYWCWW98eYs13ep5y5fbM9DeLDgcQdM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type :content-transfer-encoding; b=Q35trz2XhrDZhraG05j6yb836KFpVM1lYxC56Pi+0VhJ3DaWzZiMUE/j9Y6nNJXXVO 8oQ6cZqCxWNDg1m1yfbPLjpUF3x4mSVL7Ue3n8Yif7QqqbntAeDliwc0pIAjfdJn6t7o u04Euy7g+/4pvdk1oIjLxdHhSsFPqr7vvJCf4= Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-user@lists.gentoo.org Reply-to: gentoo-user@lists.gentoo.org MIME-Version: 1.0 Received: by 10.86.91.3 with SMTP id o3mr100286fgb.35.1232085196341; Thu, 15 Jan 2009 21:53:16 -0800 (PST) Date: Thu, 15 Jan 2009 21:53:16 -0800 Message-ID: Subject: [gentoo-user] Bash & Server Sockets From: Hilco Wijbenga To: Gentoo User Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Archives-Salt: 1d724a5e-8c37-401b-a88c-bcb7ade30835 X-Archives-Hash: 717f9385e755249a1e18640c0da7e9de Hi all, In Bash /dev/tcp/host/port can be used to write to a TCP socket. This works nicely so I was very curious whether it would work the other way too: is it possible to have a Bash script listen on a particular port as if it were a server? I couldn't find anything in the Bash manual about it. Google does find a few examples but they all use nc. But that's cheating! ;-) Is it possible with just Bash, no extra tools? (If yes, please enlighten me as to how, obviously I could not get it to work.) On a related note, I read some comments about Debian having /dev/tcp disabled in Bash because of security concerns. Would someone knowledgeable about security be able to comment on that? It doesn't make much sense to me. I mean, any Perl, Python, Ruby, etcetera script can write to a socket. Even Debian (with every option deselected) comes installed with Perl. (Yes, I installed Debian just to find out!) :-) So why should /dev/tcp in Bash be deemed such a security risk? Cheers, Hilco P.S. For the curious: #!/bin/bash exec 3<>/dev/tcp/www.google.ca/80 echo -ne "GET / HTTP/1.1\r\n">&3 echo -ne "Host: www.google.ca\r\n">&3 echo -ne "Connection: close\r\n">&3 echo -ne "\r\n">&3 cat <&3