华北电力大学网络综合实验.docx
- 文档编号:3658888
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:15
- 大小:1.04MB
华北电力大学网络综合实验.docx
《华北电力大学网络综合实验.docx》由会员分享,可在线阅读,更多相关《华北电力大学网络综合实验.docx(15页珍藏版)》请在冰豆网上搜索。
华北电力大学网络综合实验
综合实验报告
(2013--2014年度第二学期)
名称:
网络综合实验
题目:
端口扫描程序和天气查询
院系:
计算机系
班级:
学号:
学生姓名:
指导教师:
李丽芬刘晓峰曹锦纲
设计周数:
2周
成绩:
日期:
2014年6月14日
一、目的与要求
1.任务:
设计并实现一个端口扫描程序,检测某个IP或某段IP的计算机的端口工作情况。
2.目的:
加深对课堂讲授知识的理解,熟练掌握基本的网络编程技术和方法,建立网络编程整体概念,使得学生初步具有研究、设计、编制和调试网络程序的能力。
3.要求:
熟悉有关定义、概念和实现算法,设计出程序流程框图和数据结构,编写出完整的源程序,基本功能完善,方便易用,操作无误。
4.学生要求人数:
1人。
二、主要内容
1.编写一个端口扫描程序,能够显示某个IP或某段IP的计算机的某一个或某些端口是否正在工作。
基本工作过程如下:
(1)设定好一定的端口扫描范围;
(2)设定每个端口扫描的次数,因为有可能有的端口一次扫描可能不通;
(3)创建socket,通过socket的connect方法来连接远程IP地址以及对应的端口;
(4)如果返回false,表示端口没有开放,否则端口开放。
三、进度计划
序号
设计内容
完成时间
备注
1
任务布置及资料收集
第1周周一、周二
2
软件方案设计与制定
第1周周三至周四
3
编程实现
第1周周周五至第2周周二
4
程序测试与修改,撰写报告
第2周周三至周五上午
5
报告提交,软件验收
周五下午
四、设计成果要求
1.完成规定的实验任务,保质保量;
2.完成综合实验报告,要求格式规范,内容具体而翔实,应体现自身所做的工作,注重对实验思路的归纳和对问题解决过程的总结。
五、考核方式
1.平时成绩+验收答辩+实验报告;
2.五级分制。
3.
学生姓名:
艾壮
指导教师:
李丽芬刘晓峰曹锦纲
2014年6月14日
(2)天气查询
1目的与要求
1.1任务:
利用WebService技术实现天气预报查询。
1.2目的:
学习在网络应用程序中创建和使用Web服务。
WebService由于其跨平台的优越性,被越来越多的网站所重用。
了解其实现原理及使用方法,有利于了解未来的网络开发技术。
1.3要求:
利用WebService技术,实现一个查询实时天气预报的网站,要求界面美观,方便易用;通过课程设计学生应该具备初步分析、设计和开发网络应用软件的能力,具备分析与检查软件错误、解决和处理实验结果的能力。
1.4学生要求人数:
1人。
2主要内容
编写一个网站,可供用户查询全国主要城市实时的天气情况,实时信息可包括:
天气、发布时间、气温、风向、风速、湿度、能见度、日出时间、日落时间以及未来24小时的天气预报。
基本工作过程如下:
(1)了解WebService技术的原理和使用方法;
(2)寻找提供实时天气信息的Web服务;
(3)利用WebService完成查询网页与信息提供网站的链接;
(4)测试网页。
3进度计划
序号
设计内容
完成时间
备注
1
任务布置及资料收集
第1周周一、周二
2
软件方案设计与制定
第1周周三至周四
3
编程实现
第1周周周五至第2周周二
4
程序测试与修改,撰写报告
第2周周三至周五上午
5
报告提交,软件验收
周五下午
4设计成果要求
4.1完成规定的实验任务,保质保量;
4.2完成综合实验报告,要求格式规范,内容具体而翔实,应体现自身所做的工作,注重对实验思路的归纳和对问题解决过程的总结。
五、考核方式
4.平时成绩+验收答辩+实验报告;
5.五级分制。
学生姓名:
艾壮
指导教师:
李丽芬刘晓峰曹锦纲
2014年6月14日
2、综合实验正文
端口扫描程序的程序代码
#include
#include
#include
#include
#pragmacomment(lib,"ws2_32.lib")
usingnamespacestd;
typedefunsignedintuint;
vector
int
main()
{
WORDwsVersion=MAKEWORD(2,0);//socket的版本
WSADATAwsaData;//这个结构被用来存储被WSAStartup函数调用后返回的WindowsSockets数据。
它包含Winsock.dll执行的数据。
structsockaddr_insin;//sockaddr_in结构,表示socketaddressandinternetstyle
uintBeginPort;//开始端口
uintEndPort;//结束端口
uintCurrentPort;//正在扫描的端口
uinti=0;
charHostName[256];//要扫描的主机
SOCKETs;//保存创建socket时的返回值/////////////////////////
////////////////////创建一个套接口。
#include
//af:
一个地址描述。
目前仅支持AF_INET格式,也就是说ARPAInternet地址格式type:
新套接口的类型描述。
//protocol:
套接口所用的协议。
如调用者不想指定,可用0。
///////该函数如果调用成功就返回新创建的套接字的描述符
intOpenPort;//开放端口个数
OpenPort=0;
cout<<"PleaseinputtheHostName:
";
cin>>HostName;
cout<<"InputtheBeginPort:
";
cin>>BeginPort;
cout<<"InputtheEndport:
";
cin>>EndPort;
//对用户输入的端口进行判断
while((BeginPort>EndPort||BeginPort<0||BeginPort>65535||EndPort<0||EndPort>65535))
{
cout<<"Youhaveinputsomewrongparamters.Tryagain."< cout<<"PleaseinputtheHostName: "; cin>>HostName; cout<<"InputtheBeginPort: "; cin>>BeginPort; cout<<"InputtheEndport: "; cin>>EndPort; } if(WSAStartup(wsVersion,&wsaData)) { cout<<"InitialFailed! "< } cout< //循环判断范围内的端口,以判断端口是否开放,并记录结果 for(CurrentPort=BeginPort;CurrentPort<=EndPort;++CurrentPort) { s=socket(AF_INET,SOCK_STREAM,0);//s用来记录socket的返回值。 if(s==INVALID_SOCKET) { cout<<"EstablishSocketFailed."< } //给结构成员赋值 sin.sin_family=AF_INET;//可能是硬件地址。 。 sin.sin_port=htons(CurrentPort);//当前扫描的端口号 sin.sin_addr.S_un.S_addr=inet_addr(HostName);//输入ip地址用的 //建立连结 if(connect(s,(structsockaddr*)&sin,sizeof(sin))==SOCKET_ERROR) { cout<<"Port: "< Notopen."< closesocket(s);//连接失败 } else { cout<<"Port: "< Opened."< OpenPort++; v.push_back(CurrentPort);//用于数值的自动增加vector(uint)v closesocket(s); } } cout< Host"< "< cout<<"===================================================================="< for(i=0;i { cout< if((i+1)%10==0)cout< } cout< cout<<"===================================================================="< closesocket(s); WSACleanup(); return0; } 天气查询 前台界面代码: <%@PageLanguage="C#"AutoEventWireup="true"CodeBehind="WebForm1.aspx.cs"Inherits="WeatherProgram.WebForm1"%> DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http: //www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> //www.w3.org/1999/xhtml"> .style1 { margin-left: 340px;margin-top: 140px; font-size: xx-large; } body { background-image: url(image/2.jpg); background-repeat: no-repeat; } #form1 { height: 773px; width: 1176px; } .link1 { margin-left: 200px; } .link2 { margin-left: 130px; } .link3 { margin-left: 130px; } .link4 { margin-left: 130px; } .link5 { margin-left: 130px; } .link2ahover { text-decoration: underline; } style="font-family: 宋体,Arial,Helvetica,sans-serif;font-size: 60px;color: #00FFFF;">欢迎使用天气预报查询
TextBoxID="TextBox1"runat="server"Height="30px" style="margin-left: 249px;margin-top: 139px"Width="391px">
TextBox>
ButtonID="Button1"runat="server"style="margin-left: 73px" Text="查询"Height="30px"Width="109px"onclick="Button1_Click"/> LabelID="Label5"runat="server"Text="今天天气: "Height="22px"Width="81px" style="margin-left: 270px"> Label> TextBoxID="TextBox2"runat="server" style="margin-left: 0px;margin-top: 0px"> TextBox> 明天天气: TextBox ID="TextBox9"runat="server" style="margin-left: 0px;margin-top: 0px"> TextBox> LabelID="Label6"runat="server"Text="发布时间: "Height="22px"Width="81px" style="margin-left: 270px"> Label> TextBoxID="TextBox3"runat="server"style="margin-left: 0px"> TextBox> 后天天气: TextBox ID="TextBox12"runat="server"style="margin-left: 0px"> TextBox> LabelID="Label7"runat="server"Text="气温: "Height="22px"Width="81px" style="margin-left: 270px"> Label> TextBoxID="TextBox4"runat="server"style="margin-left: 0px"> TextBox> LabelID="Label8"runat="server"Text="风向: "Height="22px"Width="81px" style="margin-left: 270px"> Label> TextBoxID="TextBox5"runat="server"style="margin-left: 0px"> TextBox> LabelID="Label9"runat="server"Text="省份: "Height="22px"Width="81px" style="margin-left: 270px"> Label> TextBoxID="TextBox6"runat="server"style="margin-left: 0px"> TextBox> LabelID="Label10"runat="server"Text="城市编码: "Height="22px"Width="81px" style="margin-left: 270px"> Label> TextBoxID="TextBox7"runat="server"style="margin-left: 0px"> TextBox> 宋体,Arial,Helvetica,sans-serif;font-size: 26px;color: #000000;"> #0000FF">XX #0000FF"/>新浪 #0000FF"/>搜狐 href=style="color: #0000FF"/>网易