![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Perl CGl Programming: No experience required.
Whether youre a UNIX or Windows user, every time you do anything on a TCP/IP network, including the Internet, youre using sockets. The sockets library quickly became part of the standard UNIX distribution and its been there ever since. When Microsoft developers realized in the late 1980s that Windows would need a TCP/IP driver to plug into the Internet, they came up with an application programming interface (API) called Winsock, which, except for some functions that had to be specific to Windows, contains most of the same operations as the Berkeley sockets library.
Now, just because UNIX and Windows have sockets libraries doesnt mean that network programming is any less arcane and frustrating. Most of the things you can do with sockets are far beyond the scope of this book. Although the Perl standard library includes all of the UNIX sockets functions, programs that deal regularly with networking really should be written in a compiled language because its faster. As usual, however, Perl is dandy for small, quick network tasks. Lets take a look at one. Dealing with Internet AddressesInternet addresses come in two parts, both of which are intended primarily for human consumption, but only one of whichwith some manipulationis meaningful to computers. An Internet address is most familiar to you as a domain name such as www.alfredpacker.com. However, the name means absolutely nothing to your computer or anyone elses. It has to be associated with a numeric IP address before any software can find it. You have an example of the association on your computer, called the hosts file.
Here is an example of a line from a typical hosts file: 127.0.0.1 localhost www.alfredpacker.com Notice that the line is set up in two columns, the first containing an IP address and the second a list of domain names separated by spaces. In this example, the IP address is one that is reserved for local testing through the primary name localhost. The name that follows is known as an alias. Your hosts file is just a text file and you can put anything in it that you like, so long as you follow the two-column, IP address-domain name convention on each line. Whenever you run programs that deal with domain names, the hosts file is the first place the software looks to find the IP address. If the address isnt there, TCP/IP software checks the first domain name server in its internal list, which is usually on your Internet service providers computer. As an example of how you can use the hosts file yourself, some large networks are shielded from the world by a device called a firewall, which keeps outsiders from getting in. Insiders have to go through the firewall to get out to the Internet. In one firewall scheme, if you wanted to use the TCP/IP utility telnet to sign on to a remote system, you would have to log in to the firewall first, and software there would ask you for the name of the remote computer and pass you over to it. However, this security scheme forces you to remember the IP address of the firewall. If its address is, say, 10.64.198.7, you would have to type telnet 10.64.198.7 every time you ran it. But if you put a line in your hosts file: 10.64.198.7 firewall you could get away with entering telnet firewall and it would work just the same.
IP addresses in the form familiar to you are still meaningless to computers. The address in your hosts file actually represents a four-byte whole number, with each of the bytes separated by periods. The familiar IP address is converted into a number by the TCP/IP software before it can be used as a real Internet address. You can see exactly how this is doneand create a nice utility for yourself in the meantimeby writing a Perl program to look up names and addresses on the Internet.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. |