Programming the Network with Perl

This document was uploaded by one of our users. The uploader already confirmed that they had the permission to publish it. If you are author/publisher or own the copyright of this documents, please report to us by using this DMCA report form.

Simply click on the Download Book button.

Yes, Book downloads on Ebookily are 100% Free.

Sometimes the book is free on Amazon As well, so go ahead and hit "Search on Amazon"

It is no longer enough for today's software engineers to be able to program the computer and debug programs - the modern programmer needs to know how to program the network and debug communications. This book shows you how, using Perl.

Originally created as a tool for System Administrators, the Perl Programming languauge has matured into a powerful, yet easy-to-use, general-purpose programming language. Widely used on the Internet, Perl is the programming language of choice when it comes to adding dynamic content to websites using the Common Gateway Interface (CGI). Its strengths - simplicity, power and adaptability - make it an excellent vehicle with which to study computer networking and to program computer networks in general.

In Programming the Network with Perl, Paul Barry applies Perl to the study of tradiitonal computer networking topics. After an introductory tutorial to the Perl programming language appropriate for the non-Perl programmer, five key computer networking topics are examined from the perspective of the software engineer using Perl.

  • Snooping details the creation of a successively more functional set of Ethernet Network Analaysers and cumulates in the development of The Network Debugger, a tool for monitoring the traffic generated by both standard and custom-built networked applications.
  • Sockets details how to use Perl to create custom networked applications by programming the TCP/IP transport protocols (TCP and UDP), using the Client/Server Model and the standard Berkeley Socket API.
  • Protocols details just how easy it is to program the HTTP (web), SMTP (e-mail), NNTP (news) and TELNET (remote login) protocols with Perl. HTML parsing is also described.
  • Management uses Perl to program the Simple Network Management Protocol (SNMP), the cornerstone network management technology on the modern Internet.
  • Mobile Agents is a presentation of one of the technologies that can be added to Perl to provide for the development of custom networked applications that can transport themselves from network device to network device while executing.
Each chapter concludes with a set of Print and Web Resources, as well as suggested Exercises to support further study by the reader.

The associated website provides Perl links, downloadable source code, presentation materials (in PDF format), and instructions for joining the pertnetbook discussion mailing list.

Author(s): Paul Barry
Publisher: Wiley
Year: 2002

Language: English
Pages: 397

Programming the Network with Perl......Page 3
Contents......Page 9
Preface......Page 15
1.1 Perl’s Default Behaviour......Page 19
1.1.1 Our first Perl program......Page 20
1.1.3 The strange first line explained......Page 21
1.2 Using Variables in Perl......Page 22
1.2.1 One of something: scalars......Page 23
1.2.2 A collection of somethings: arrays and lists......Page 24
1.2.3 Hashes......Page 26
1.2.4 References......Page 27
1.2.6 Scoping with local, my and our......Page 30
1.3.1 if......Page 31
1.3.2 The ternary conditional operator......Page 32
1.3.4 for......Page 33
1.3.7 foreach......Page 34
1.3.9 eval......Page 35
1.3.10 Statement modifiers......Page 36
1.4 Boolean in Perl......Page 37
1.5 Perl Operators......Page 38
1.6.1 Processing parameters......Page 39
1.6.2 Returning results......Page 40
1.6.4 In-built subroutines......Page 41
1.7 Perl I/O......Page 44
1.7.1 Variable interpolation......Page 46
1.8 Packages, Modules and Objects......Page 47
1.8.2 Objects......Page 48
1.8.3 The joy of CPAN......Page 49
1.11 Print Resources......Page 50
1.12 Web Resources......Page 51
2 Snooping......Page 53
2.1 Thank You, Tim Potter......Page 54
2.2.1 Installing NetPacket::*......Page 55
2.2.2 Installing Net::Pcap......Page 56
2.2.4 Online documentation......Page 57
2.2.5 Configuring your network interface......Page 58
2.3 Building Low-Level Snooping Tools......Page 59
2.3.1 loop = open + next......Page 60
2.3.2 Optional parameters: loop and open......Page 61
2.3.4 Ethernet Analysis......Page 63
2.3.5 EtherSnooper (v0.01)......Page 66
2.3.6 EtherSnooper (v0.02)......Page 70
2.3.7 EtherSnooper (v0.03)......Page 73
2.3.8 Displaying IP addresses......Page 76
2.4 Snooping IP Datagrams......Page 81
2.4.1 EtherSnooper (v0.05)......Page 82
2.4.2 EtherSnooper (v0.06)......Page 85
2.5 Transport Snoopers......Page 87
2.5.2 Preparing to snoop TCP......Page 88
2.5.3 The TCP and UDP gotcha!......Page 89
2.5.4 Application traffic monitoring......Page 93
2.5.5 EtherSnooper (v0.07)......Page 99
2.6 The Network Debugger......Page 101
2.6.2 Storing captured results......Page 103
2.6.3 The NetDebug source code......Page 104
2.8 Print Resources......Page 113
2.9 Web Resources......Page 114
3.1 Clients and Servers......Page 117
3.1.1 Client characteristics......Page 118
3.2 Transport Services......Page 119
3.2.1 Unreliable transport......Page 120
3.2.2 Reliable transport......Page 121
3.3 Introducing the Perl Socket API......Page 122
3.4.2 Socket addresses......Page 123
3.4.4 getprotobyname and getprotobynumber......Page 124
3.4.5 gethostbyname and gethostbyaddr......Page 125
3.5.2 The first UDP server......Page 126
3.5.3 The first UDP client......Page 129
3.6 Genericity and Robustness......Page 130
3.7 UDP Is Unreliable......Page 134
3.7.1 No flow control......Page 135
3.8 Sending and Receiving with UDP......Page 136
3.9 Dealing with Deadlock......Page 138
3.9.1 Specifying a time-out......Page 139
3.9.2 Checking for data......Page 141
3.9.3 Spawning a subprocess......Page 143
3.10 TCP Clients and Servers......Page 148
3.10.1 The first TCP server......Page 149
3.10.2 The first TCP client......Page 152
3.11 A Common TCP Gotcha......Page 158
3.12 More TCP Socket Communication......Page 161
3.12.1 The remote syntax checker server......Page 162
3.12.2 The remote syntax checker client......Page 165
3.13 The Concurrent Syntax Checker......Page 168
3.14 Object-Oriented Sockets......Page 171
3.14.2 IO::Socket::INET......Page 172
3.14.3 An object-oriented client and server......Page 174
3.16 Print Resources......Page 176
3.17 Web Resources......Page 177
4.1 Gotcha!......Page 179
4.1.1 What’s the deal with newline?......Page 180
4.2.1 HTTP requests and responses......Page 182
4.3 The World’s Worst Web Browser......Page 183
4.3.1 Embedded graphics......Page 186
4.3.2 A persistent wwwb......Page 187
4.3.3 A better get_resource......Page 190
4.4 HTTP Status Codes......Page 192
4.5 It’s the Gisle and Graham Show!......Page 196
4.5.1 Getting libwww-perl and libnet......Page 197
4.6 The Library for WWW Access in Perl......Page 198
4.7 The LWPwwwb Program......Page 199
4.8 Doing More with LWPwwwb......Page 202
4.8.1 Parsing HTML......Page 203
4.8.2 Some parsewwwb examples......Page 205
4.8.3 The HTML::Parser examples......Page 207
4.9.1 The custom Web server source code......Page 208
4.9.2 The custom Web server in action......Page 214
4.10 The libnet Library......Page 215
4.10.1 Working with Usenet......Page 216
4.10.2 The news reading source code......Page 217
4.11.1 The simple mail transfer protocol......Page 223
4.11.2 The Net::SMTP module......Page 228
4.11.3 Creating simplehttp2d......Page 229
4.12.1 Installing Net::Telnet......Page 231
4.12.2 A Net::Telnet example......Page 232
4.15 Web Resources......Page 235
5 Management......Page 239
5.2 Doing the Ping Thing......Page 240
5.2.1 Some ping examples......Page 241
5.3 Doing the Net::Ping Thing......Page 243
5.4 Tracing Routes......Page 245
5.4.1 How traceroute works......Page 246
5.5.1 A little SNMP history......Page 247
5.6 The SNMP Management Framework......Page 248
5.7.1 The TCP/IP MIB......Page 249
5.8.2 A brief tour of SNMPv1, SNMPv2 and SNMPv3......Page 253
5.9 The Net::SNMP Module......Page 255
5.9.1 The Net::SNMP methods......Page 256
5.10 Working With Net::SNMP......Page 258
5.10.1 Working with mnemonic object identifiers......Page 260
5.10.2 The udpstats source code......Page 261
5.10.3 The howlongup program......Page 265
5.11 What’s Up?......Page 267
5.11.1 Being more careful......Page 272
5.12 Setting MIB-II Data......Page 274
5.13 IP Router Mapping......Page 276
5.15 Print Resources......Page 284
5.16 Web Resources......Page 285
6.1 What is a Mobile Agent?......Page 287
6.2.1 Revisiting multiwho......Page 288
6.2.2 Revisiting ipdetermine......Page 289
6.3 Mobile-Agent Advantages/Disadvantages......Page 290
6.4.1 Preparing Perl for mobile agents......Page 292
6.5 The Agent.pm Module......Page 293
6.7 The Default Mobile Agent......Page 294
6.8 A Launching Mobile-Agent Environment......Page 298
6.9 A One-Shot Location......Page 300
6.10 Relocating To Multiple Locations......Page 302
6.10.2 Identifying multiple locations......Page 303
6.10.3 A multi-location mobile agent......Page 305
6.11 The Mobile-Agent multiwho......Page 310
6.12 The Mobile-Agent ipdetermine......Page 311
6.13 The Cloning Mobile-Agent ipdetermine......Page 315
6.14 Other Perl Agent Examples......Page 322
6.17 Web Resources......Page 323
Appendix A. Essential Linux Commands......Page 325
Appendix B. vi Quick Reference......Page 329
Appendix C. Network Employed......Page 333
Appendix D. Sample NetDebug Results......Page 335
Appendix E. The OIDs.pm Module......Page 381
Index......Page 387