[Pythonmac-SIG] Off-topic : /dev/tcp
Philippe de Rochambeau
philippe at wwphi.net
Tue Mar 30 15:50:59 EST 2004
Hello,
sorry to have waisted your fellows' time for nothing. I just wanted to
learn yet another way to fetch data from the Web. Here's the code. It
is a lot more primitive than the equivalent python code, of course. It
works on macosx.
PR
===============
#!/bin/bash
shopt -o -s nounset
declare LINE
declare -rx SCRIPT=${0##*/}
printf "Connecting to host\n"
exec 3<> /dev/tcp/www.apple.com/80
printf "Sending request to host\n"
printf "%s HTTP/1.0\r\n" "GET /" >&3
printf "Accept: text/html, text/plain\r\n" >&3
printf "Accept-Language: en\r\n" >&3
printf "User-Agent: %s (Bash Script)\r\n" "$SCRIPT" >&3
printf "\r\n" >&3
printf "Receiving page\n"
printf "%s\n" "----------------"
while read LINE <&3 ; do
printf "%s\n" "$LINE"
done
exit 0
==========
On 30 mars 04, at 22:03, Cameron Laird wrote:
>> From pythonmac-sig-bounces at python.org Tue Mar 30 14:44:53 2004
>> .
>> .
>> .
>> The book "Linux shell scripting with Bash" says that you can open
>> network connections with /dev/tcp as in
>
>> exec 3<> /dev/tcp/localhost/80
>
>> The author then gives an example in shell script of how to use
>> /dev/tcp
>> to connect to a webserver.
>
>> I just wanted to investigating this as an alternative to a Python +
>> httplib + wxWindows script which I wrote.
>> .
>> .
>> .
> Oh, *that*; I would have summarized that in quite different words.
>
> I'm far more often involved in moving people from *sh to Python,
> rather than the other way around. Let's give this a try, though.
>
> Anyway, /dev/tcp isn't a "real" inode, it's just a syntax bash and
> ksh use for networking. So, if I understand you correctly, you
> want to do a bit of socket programming under MacOS X with bash.
> Well, that's easy enough ... no, wait; is all you want to script
> downloading of a few http: documents? I think there's an even
> easier way to achieve that.
>
More information about the Pythonmac-SIG
mailing list