File: silva.html

package info (click to toggle)
lg-issue49 1-5
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,280 kB
  • ctags: 255
  • sloc: makefile: 36; tcl: 19; sh: 15; perl: 1
file content (312 lines) | stat: -rw-r--r-- 13,410 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
<!--startcut  ==============================================-->
<!-- *** BEGIN HTML header *** -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML><HEAD>
<title>Developing Web Applications - Part II LG #49</title>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000">
<!-- *** END HTML header *** -->

<!-- *** BEGIN navbar *** -->
<A HREF="lg_toc49.html"><IMG ALT="[ Table of Contents ]" 
	SRC="../gx/indexnew.gif" WIDTH=163 HEIGHT=60 ALIGN=bottom ></A>
<A HREF="../lg_frontpage.html"><IMG ALT="[ Front Page ]" 
	SRC="../gx/homenew.gif" WIDTH=163 HEIGHT=60 ALIGN=bottom></A>
<A HREF="pramode.html"><IMG ALT="[ Prev ]" SRC="../gx/back2.gif" WIDTH=41 HEIGHT=60 ALIGN=bottom></A>
<A HREF="../lg_faq.html"><IMG ALT="[ Linux Gazette FAQ ]" 
	SRC="./../gx/dennis/faq.gif"WIDTH=163 HEIGHT=60 ALIGN=bottom></A>
<A HREF="silva2.html"><IMG ALT="[ Next ]" SRC="../gx/fwd.gif" WIDTH=41 HEIGHT=60 ALIGN=bottom  ></A>
<!-- *** END navbar *** -->

<!--endcut ============================================================-->

<H4>
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>

<P> <HR> <P> 
<!--===================================================================-->

<center>
<H1><font color="maroon">Developing Web Applications - Part II</font></H1>
<H4>By <a href="mailto:afsilva@liberty.edu">Anderson Silva</a></H4>
</center>
<P> <HR> <P>  

<!-- END header -->





<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: 8.333333mm; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
As I promised, I was going to give you guys another example of a php3 program.
This program is a very simple program, and yet somewhat useful.</div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: 8.333333mm; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
One night, I was at the university working and I tried to call home to
talk to my wife. Unfortunately, I had left my computer connected that day,
and could not get through. So, since my computer was running Apache, I
decided to scan through the IPs of my ISP , and find out which computer
was my computer, so I could telnet to it, and remotely disconnect it.</div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: 8.333333mm; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
The fastest, and simplest way to do this was either through php3 or java,
but since I am not very fond of java applets, I decided to do it in php3.</div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
And here is how it goes:</div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&lt;?</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
//Author: Anderson Silva</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
//Date: September, 1999</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
//Opens socket and goes through a bunch of sequential IPs, and</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
//it returns all the address that have a web server running.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">&nbsp;
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
// This loop will go through all addresses in the block 10.0.0.x</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
// The 10.0.0.x series is a fictional example, these IPs are normally</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
// for intranet addresses, I am just trying to keep my ISP safe from</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
// all of you guys :-)</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
for($i=1; $i &lt; 256; $i++)</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
{</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// $path is the variable that will hold the URL you are testing.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$path = "http://10.0.0.".$i;</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">&nbsp;
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// Opens socket on server PAI, port 80.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$fp = fsockopen("pai", 80, &amp;$errno, &amp;$errstr);</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">&nbsp;
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// Sends the HTTP request that returns the info we need to know.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fputs($fp,"GET $path HTTP/1.0\n\n");</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
set_socket_blocking($fp, false);</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">&nbsp;
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// This is the string we wait for as a reply to the HTTP request.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$str2 = "HTTP/1.0 200 OK";</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">&nbsp;
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// Gives the program 2 seconds to try to connect to the server.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Sleep(2);</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; ">&nbsp;
<br><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Captures the line from the
HTTP request.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
$line = fgets($fp, 16);</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// If str2 is the same line, then we have a match, and there is a web</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// server running. Then go ahead and show me the name of the server with</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
// a link to it.</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
if (strcmp($line, $str2) == 0)</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
echo "&lt;A HREF=".$path.">".gethostbyaddr($pathhost)."&lt;/a>&lt;br>\n";</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
fclose($fp);</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>&nbsp;&nbsp;&nbsp;
}</b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: normal; color: Black; background-color: White; "><b>?></b></div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: 8.333333mm; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
One important observation, this process is very simple, but it is very
inefficient, since for every IP you check you will wait a maximum of 2
seconds. So, don't abuse this script, because you will probably get a time
out operation from your web server, or you will be stuck waiting for all
the iterations for a long time.</div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">
<div style="text-indent: 0.00mm; text-align: left; line-height: 8.333333mm; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
But still, it is a good example of what you as a home user can do with
php3.</div>
</div>

<div style=" 
padding: 0.00mm 0.00mm 0.00mm 0.00mm; ">&nbsp;
<div style="text-indent: 0.00mm; text-align: left; line-height: 8.333333mm; color: Black; background-color: White; ">&nbsp;&nbsp;&nbsp;
Next month, I will write yet another example of php3 program, this time
I will show you how to create your own guest book, using php3 and mySQL.</div>
</div>




<!-- *** BEGIN copyright *** -->
<P> <hr> <P> 
<H5 ALIGN=center>

Copyright &copy; 2000, Anderson Silva<BR> 
Published in Issue 49 of <i>Linux Gazette</i>, January 2000</H5>
<!-- *** END copyright *** -->

<!--startcut ==========================================================-->
<P> <HR> <P>
<!-- *** BEGIN navbar *** -->
<A HREF="lg_toc49.html"><IMG ALT="[ Table of Contents ]" 
	SRC="../gx/indexnew.gif" WIDTH=163 HEIGHT=60 ALIGN=bottom ></A>
<A HREF="../lg_frontpage.html"><IMG ALT="[ Front Page ]" 
	SRC="../gx/homenew.gif" WIDTH=163 HEIGHT=60 ALIGN=bottom></A>
<A HREF="pramode.html"><IMG ALT="[ Prev ]" SRC="../gx/back2.gif" WIDTH=41 HEIGHT=60 ALIGN=bottom></A>
<A HREF="../lg_faq.html"><IMG ALT="[ Linux Gazette FAQ ]" 
	SRC="./../gx/dennis/faq.gif"WIDTH=163 HEIGHT=60 ALIGN=bottom></A>
<A HREF="silva2.html"><IMG ALT="[ Next ]" SRC="../gx/fwd.gif" WIDTH=41 HEIGHT=60 ALIGN=bottom  ></A>
<!-- *** END navbar *** -->
</BODY></HTML>
<!--endcut ============================================================-->