C语言cgi(1)
1
Columbia University
cs3157 – Advanced Programming
Summer 2014, Lab
#2, 60ish points
June 9, 2014
Follow these step-by-step instructions. This
lab must be submitted electronically by Monday June
16th, 11:55 pm.
The
point of the labs is to teach and reinforce specific programming concepts, cut
time off your
homework assignment while trying to maintain your interest. If
you find them tedious or pointless, please
don’t hesitate to bring it to your
instructor’s attention (the same applies the opposite).
Step 1. Visual Editor
and Debugging (5 points)
A debugger is a program that allows you (the
programmer) to step through an executing program (i.e live,
real time) and
track internal information and monitor progress. This allows you to monitor
logical
progress and also track down errors.
Perldoc perldebug
Will
give you more information about the debugging environment. Executing the perl
command with the
-d flag will start perl in debugging mode. Try it….take one
of the scripts from lab1 and execute it
perl -d something.pl
(h gives you
help, q to quit, v shows you some code around you, etc).
The nice part about
eclipse is the ability of running the debugger in a visual environment, so that
you
don’t need to memorize random key commands. (That is a good thing and
bad). You have a choice if you
want to run it from the command line or visual
environment. Be aware that certain specific versions of
eclipse (older) and
certain versions of EPIC (older) have issues with the debug system, which causes
it to
work every other time J
Write up a paragraph or two about your
experience in running the debugging environment on one of the
lab scripts
from last lab and over the lab 2 assignments. Answer the following questions
after you are
done with the lab:
1) After using the debugger, did your
code work become easier or harder ?
2) Any issues with the perl debugger in
the clic lab ?
3) After using it to watch a variable what can you say about
perl variable scope ?
4) What is the difference between stepping over and
stepping through in regards to subs ?
5) How does the average rainfall in the
Sahara affect Perl development ?
Step 2 (20 points)
Create a perl file
called step2.pl. I am providing a file called “testip” to be used as a test
file.
2
Background information: Computer on the internet are identified
using a few standard conventions.
One of them are IP address. The format for
IP version 4, is 4 sets of numbers between 0-255. So your own
machine might
be 128.59.18.1 etc
1) Given a specific file (passed as a command line
argument (important) ) which contains among
other things, IP addresses, I
would like you to locate and count
any IP address in the file. For example
the ip address 255.234.255.1 (4 numbers separated by a
period).
NOTE: you
need to make sure none of the numbers are not larger than 255
2) I would also
like a printout of all the IP addresses, and the number of times it was seen in
the file.
Addresses can appear multiple times on a line…keep that in
mind.
3) I would like to know how much time has passed from the beginning and
end of the program run,
we would like to see how much time it took to
analyze. Lookup localtime command to see how to
grab the current time.
You
will need to loop through the file, find the ip address (use the regular
expressions covered in class on
Monday), and then keep a count of number of
each one seen. Once done, you can print them out in sorted
order in the
following format:
Processed file YYYYY
Number of unique IP:
3
123.123.123.123 9
12.12.112.2 7
23.125.123.256 2
..
File
analyzed in: 1 minute and 23 seconds
Step 3: (4 points)
Consider the
following Perl program:
#!/usr/bin/perl
use strict;
my(@list) = (5,
"Todd", 3, 2);
$list[2] += 4;
print "M1: ".$list[0]." ".$list[1]."
".$list[2]." ".$list[3]."\n";
($list[1], $list[3]) = funky(@list);
print
"M2: ".$list[0]." ".$list[1]." ".$list[2]." ".$list[3]."\n";
## End of main
program
sub funky {
my($v1, $v2, $v3) = @_;
print "F1: "." ".$v1."
".$v2." ".$v3.
" ".$_[0]." ".$_[1]." ".$_[2]."
".$_[3]."\n";
$_[0]++;
print "F2: "." ".$v1." ".$v2." ".$v3.
"
".$_[0]." ".$_[1]." ".$_[2]." ".$_[3]."\n";
$v3 = "Bill";
print "F3: "."
".$v1." ".$v2." ".$v3.
" ".$_[0]." ".$_[1]." ".$_[2]."
".$_[3]."\n";
3
return($v3, $v2);
} ## Of function FUNKY
What did
you expect the output to look like and what did it actually look like ? Explain
(based on what
we covered in class) what is going on…
Step 4 New Process
monitor (20 points)
As demo-ed in class, you will write a simple process
monitor. You will use the output of the (ps –aux)
command to pick out all the
running pid->program names every 5 seconds. You will run your program
for
10 minutes printing out when a program starts, or stops.
As we
discussed you will need to run the ps command and then create a map list of the
current running
pid and process names. You will compare current to last map
(so if its at 10 seconds, you need to look
back at 5 seconds) for any
processes (pid) which are new to say process is new. Use the old one to look
at
the new one to detect dead process id.
Most of the code was demo-ed in
class, type it up and add comments.
Step 5: Moving information over CGI Intro
(4 points)
We started to talk about CGI in the last class. Forms are simple
ways of feeding information to the user
and having them interact with your
script in some way.
Here is your chance to start to play around with it.
Create a HTML page (feel free to use eclipse or your
favorite text editor)
(step5.html) should have the following code in
it:
<html><head><title>Step2
webpage</title></head>
<body>
<form
action=”step5a.pl.cgi” method=POST>
Enter something:
<input
type=”text” name=”t1”>
<input type=”submit”
value=”testpost”></form>
<HR>
<form
action=”step5b.pl.cgi” method=GET>
Enter Some text:
<input
type=”text” name=”t2”>
<input type=”submit”
value=”testget”></form>
</body>
</html>
step5a.pl.cgi
and step5b.pl.cgi should look like:
use strict;
4
my $time =
localtime;
print "Content-type: text/html\n\n";
print
<<END_OF_PRINTING;
This is the time :
$time
END_OF_PRINTING
foreach my $vars (sort keys %ENV){
print
"<b>$vars</b>=";
print "$ENV{$vars}<BR>";
}
Describe
in a short paragraph what you see is the difference between get and post when
running the
cgi script. Do a quick search and read up on get and post in a
general sense. Which do you think is a better
way to work with ??
Note:
the webserver has perl in /usr/bin/perl
Step 6: More CGI and more basic
practice (5 points):
Copy and adopt the previous html file to a new file
called Step6.html. Have it call step6a.pl.cgi and
step6b.pl.cgi . In both
cases you need to process and display the input passed in, as a simple html
page
saying
I was given Key = …. With a value of = …
(for both input
types).
Hint: This means you need to parse out the arguments passed in.
remember to first split around the & sign
and then around the equal sign.
Example:
my ($pairs,$key,value);
foreach $pairs (split /&/
$inputstring){
#now cut the $pairs around the equal sign …..
Hint2: one of
the methods passes user input through ENV and one passes it through STDIN, but
you still
ENV for the length (see read method in perl)
HINT3: the scripts
are basically the same, get one to work and then copy and convert it for the
other task.
C语言cgi(1)的更多相关文章
- 搭建简易的c语言与python语言CGI和Apache服务器的开发环境
搭建简易的c语言CGI和Apache服务器的开发环境 http://www.cnblogs.com/tt-0411/archive/2011/11/21/2257203.html python配置ap ...
- 基于windows IIS的C语言CGI WEB服务器环境搭建
网页编程对我来说特别亲切,因为我就是从html.ASP.PHP一步步接触编程的.自己的编程爱好也是从那里一点一点被满足.不过离开大学之后很久没有碰过WEB了,最近看到嵌入式中的涉及到的web服务器,了 ...
- C语言 cgi(3)
1cs3157 – Advanced ProgrammingSummer 2014, Project 1, 150 pointsJune 17, 2014Follow these step-by-st ...
- C语言 cgi(2)
1Columbia Universitycs3157 – Advanced ProgrammingSummer 2014, Lab #3, 40 pointsJune 10, 2014This lab ...
- c语言cgi笔记
直接输出接收的数据 #include <stdio.h>#include <stdlib.h>main(){int i,n;printf ("Content-type ...
- 几种语言的CGI编程
为了了解PHP.JSP.ASP出现之前人们写网站的方法,洒家研究了一波CGI,使用C.Python.batch.shell script语言写了几个简单的网页. CGI即通用网关接口,指web服务器调 ...
- CGI(通用网关接口)
公共网关接口 CGI(Common Gateway Interface) 是WWW技术中最重要的技术之一,有着不可替代的重要地位.CGI是外部应用程序(CGI程序)与Web服务器之间的接口标准,是在C ...
- cgic 写CGI程序
CGIC是C语言CGI库函数,用于编写CGI程序 CGIC 主要完成以下功能: * 对数据进行语法分析 * 接收以 GET 和 PSOT 两种方式发送的数据 * 把 FORM 中的不同域连接成连续的串 ...
- libctemplate——C语言模块引擎简介及使用
前言 由先声明此libctemplate不是Google那个ctemplate.这个库是用C语言实现的,只有一个实现文件和一个头文件.Gooogl的ctemplate是C++实现的,和线程还扯上了关系 ...
随机推荐
- 14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器
14.6.2 Moving or Copying InnoDB Tables to Another Machine 移动或者copy InnoDB 表到另外的机器 这个章节描述技术关于移动或者copy ...
- windows系统port监听
通常情况下.假设想发现全部已经使用的和正在监听的port,我们能够使用netstat命令. netstat并不是一个port扫描工具.假设你想扫描计算机开放了哪些port的话.建议使用本文介绍的方法. ...
- 三次握手wireshark抓包分析,成功握手和失败握手
启动 点击start出现下面的对话框 wireshark是捕获机器上的 某一块网卡的网络包,当机器上有多块网卡的时候,需要选择一个网卡进行捕获操作. 选择网卡 >主页面上,直接点击选中后star ...
- 给c++程序员的一份礼物——常用工具集
给c++程序员的一份礼物——常用工具集 [声明]如需复制.传播,请附上本声明,谢谢.原文出处:http://morningspace.51.net/,moyingzz@etang.com 所谓&quo ...
- VC 中与字符串相关的宏 _T、TEXT,_TEXT、L 的作用(简单明了)
一. 在字符串前加一个L作用: 如 L"我的字符串" 表示将ANSI字符串转换成unicode的字符串,就是每个字符占用两个字节. strlen("as ...
- c++(重载、覆盖、隐藏)
源地址:http://www.cnblogs.com/qlee/archive/2011/07/04/2097055.html 成员函数的重载.覆盖与隐藏成员函数的重载.覆盖(override)与隐藏 ...
- Android Studio之同一窗口打开项目
Android Studio默认新打开的项目都是重新打开一个窗口,和原项目窗口同时存在,如果打开多个项目,则有很多窗口同时打开,怎么根据需要决定自己以何种方式打开呢? 1.设置打开新项目的方式 第一项 ...
- 文件比较,文件夹比较-- vimdiff,beyond compare, compare suite, WinMerge,Kdiff3
文件比较,文件夹比较-- vimdiff,beyond compare, compare suite, WinMerge,Kdiff3 有一个项目的源码包需要比较,400M以上,这就要找个好的工具了 ...
- operator= 复制操作符的意外
首先,看以下的代码的输出时什么: 上述代码做了最理所当然的事.就是将Derived的两个对象进行了交换.可是通过指针进行的赋值输出却不是预期的: 居然调用的是Base的operator=,也就意味着我 ...
- POJ 1325 ZOJ 1364 最小覆盖点集
题意:有A,B两台机器, 机器A 有 n个模式(0, 1, 2....n-1),同样机器B有m个模式, 两个机器一开始的模式都为0,有k个作业(id,x,y) 表示作业编号id, 该作业必须在A机器在 ...