Saturday, November 12, 2011

Testing Ping based random number generator.

If you want to see how this works read:  Generation of Random Number from PING

Below is that random number generator put in to CGI form to run under Apache.
It returns grey levels in a table to provide a visual confirmation of it's output.

If you make the effort to try this code, please leave a short comment.

It's part of a effort to demonstration the use of BASH in making CGI based Applications.

#!/bin/bash

echo "Content-type: text/html"
echo
echo "<html><body>"
echo "<table border=2 cellpadding=2 cellspacing=2>"

target=localhost

c=0
while [ $c -lt 32 ]
do
c=$[$c+1]

echo "<tr>"

{
echo "obase = 16"
ping -c 32 -i 0.2 $target |\
grep "time=" |\
sed \
-e 's/[a-z \.(),_:+=]//g' \
-e 's/\(.\)/\1+/g' \
-e 's/^\(.*\)+$/(\1)% 16/'
} |\
bc |\
awk '{print "<td bgcolor=\"#"$1$1$1$1$1$1"\">"$1"</td>" }' |\
tr -d '\n'

echo "</tr>"

done

echo "</table>"
echo "</body></html>"


Below is a sample of the output.


D89BFCDB07AEEFBBF028F7E1FBE410FA
86DEFAF5CACC9ECDB0EEB7FEDDE26EAD
BDC9092DF7DAB0AC1F5AD0DFE3F26A7F
88FEAD6C16D6AA0DB226AE9AB30DEBF8
5EDA0FAECACE9ECC3DF7B8D0F1ECE8CE
C4AD900EF5D7E81F2FD88C1BBE2D19AD
C98902D2349CAF9023FA8BBEF0DE2CCE
5CCA1122FC9A9BC40E4A89FC14E35DAD
A6EBBDF308B798AC1FFCF9C902DF59DF
98DFD9FF3A8AF1FFCCFB9FBBDBC33FBB
9D8709E11AD8F013FFEDBDF800C23BFA
7DF9CE0D1CA9AB2402D86E9F0E20FE08
CBA998BEE9B98D3DB01DAB9BAE4469F0
A8E7021DC7D8C2ABE50A8FEABF1347D0
9B9EB2AEE6ABEBEE13596A0BBE005A7E
9A679203F896B9C0D45BC1A91B546CF0
BCF0BAF116AE7DCCBDDEAACDBEE038EF
4ABB21B2DC58ECCE32167BDD2E3509E9
B68AA03FF85CB9ABF03C6A8CBCE11EEA
ADA6B1CB15B7F1EC046AC8A9FF143AD0
A9DB1AC21C88A8CFBDF8F1B0DC0357BE
858EEBEBE49D7CC3C01989AEEB44FC9E
ADDFFBABC89DBC22025DE7CCE1C16878
B5BFD20E0AD7BAE1EE59AFA90C11E7DB
CE7BFBE325D899AAD11DFAECDD14470A
7B8CB1EF3480BA1A354B6CBF3F446BA1
56CEBEDFDADC0CC321D9AC9CE1044DDB
6AE9BC132ACF7FF020CB790F2B001FFF
AFCBEEA349BBAB1C210AC7CDBEC01DCB
9F9E9EF0D3BCD1C1E2FABEDAF20D6ADE
9DD9FD121598ADA0F31CCB7DB2470EF1
57091BCEC47F8CDF1F1D7E8ECFD3060A

No comments: