8实验报告张期末_第1页
8实验报告张期末_第2页
8实验报告张期末_第3页
8实验报告张期末_第4页
8实验报告张期末_第5页
已阅读5页,还剩20页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

时间:2015年6月21日星期二第3、4节地点:理工楼1#208 姓名:张琪琪班级:计本8班WindowSocket技术(SocketAPIMFCSocket相关类,WindowSocket技术(SocketAPIMFCSocket相关类,具体应用类型可包含(但不限6Windows7,VC++6.0#include"stdafx.h"#include"PortScan.h"#include"MainFrm.h"#include"PortScanDoc.h"#include"Splash.h"#ifdef#definenew#undefstaticcharTHIS_FILE[]= FILE;////NOTE-theClassWizardwilladdandremovemappingmacros DONOTEDITwhatyouseeintheseblocksofgenerated//StandardfilebaseddocumentcommandsON_COMMAND(ID_FILE_NEW,CWinApp::OnFileNew)//CPortScanApp{//TODO:addconstructioncode//Placeallsignificantinitializationin}//TheoneandonlyCPortScanAppobjectCPortScanApptheApp;//CPortScanAppBOOL{//CG:ThefollowingblockwasaddedbytheSplashScreen//---new\{\CCommandLineInfo\\\\}if{returnFALSE;}//Standard//Ifyouarenotusingthesefeaturesandwishtoreducethe ofyourfinalexecutable,youshouldremovefromthe thespecificinitializationroutinesyoudonot#ifdef //CallthiswhenusingMFCinasharedDLLEnable3dControlsStatic();//CallthiswhenlinkingtoMFCstatically//Changetheregistrykeyunderwhichoursettingsare//TODO:Youshouldmodifythisstringtobesomething//suchasthenameofyourcompanyororganization.SetRegistryKey(_T("PortScanning,(C)Byrsnm@")); //LoadstandardINIfileoptions(including//Registertheapplication'sdocument Document serveastheconnectionbetweendocuments,framewindowsandCSingleDocTemplate*pDocTemplate;pDocTemplate=newCSingleDocTemplate( //mainSDIframewindow//Parsecommandlineforstandardshellcommands,DDE,fileopenCCommandLineInfocmdInfo;//Dispatchcommandsspecifiedonthecommandlineif(!ProcessShellCommand(cmdInfo))return//Theoneandonlywindowhasbeeninitialized,soshowandupdateit.//---newreturn}//CAboutDlgdialogusedforAppclassCAboutDlg:public{//Dialogenum{IDD=IDD_ABOUTBOX//ClassWizardgeneratedvirtualfunctionvirtualvoidDoDataExchange(CDataExchange* //DDX/DDV//Implementation//NomessageCAboutDlg::CAboutDlg():{}voidCAboutDlg::DoDataExchange(CDataExchange*{}//Nomessage//AppcommandtorunthedialogvoidCPortScanApp::OnAppAbout(){CAboutDlgaboutDlg;}//CPortScanAppmessage//---new{//CG:ThefollowinglineswereaddedbytheSplashScreencomponent.if(CSplashWnd::PreTranslateAppMessage(pMsg))returnreturn}#include"stdafx.h"#include"PortScan.h"#include"PortScanDoc.h"#include"MainFrm.h"#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#include<io.h>#ifdef#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]= FILE;//BEGIN_MESSAGE_MAP(CPortScanView,CFormView)ON_BN_CLICKED(IDC_RADIO_RANGE,OnRadioRange)ON_BN_CLICKED(IDC_BUTTON_SCAN,OnButtonScan)ON_BN_CLICKED(IDC_BUTTON_STOP,OnButtonStop)ON_COMMAND(ID_FILE_SAVE,OnFileSave)//CPortScanView:{//TODO:addconstructioncodeherem_pBrush=newCBrush;//m_clrBk=RGB(0x00,0x00,0x77);m_clrText=RGB(0xff,0xff,0x00);m_pColumns=newCStringList;m_bSinglePort=m_nMaxAttempts=1; //defaultvalue,Thisvaluehasbeensetonthewindowm_pStatusList=newCPtrList;}{if{//FirstEmptytheportstatusPOSITIONp=m_pStatusList->GetHeadPosition();while(p){POSITIONtemp=ifdelete}//Thenremoveitfromheap:deletem_pStatusList;}ifdelete}{DDX_Control(pDX,IDC_EDIT_ATTEMPTS,m_cAttempts);DDX_Control(pDX,IDC_BUTTON_STOP,m_cBtnStop);DDX_Control(pDX,IDC_LIST_RESULT,m_cResult);DDX_Control(pDX,IDC_BUTTON_SCAN,m_cBtnScan);DDX_Control(pDX,IDC_IP_ADDRESS,m_cIP);DDX_Control(pDX,IDC_EDIT_SINGLE_PORT_FROM,m_cPortFrom);DDX_Control(pDX,IDC_EDIT_SINGLE_PORT,m_cSinglePort);}{//TODO:ModifytheWindowclassorstyleshereby return}void{m_parent=(CMainFrame*)GetParent(); }//CPortScanView#ifdef{}voidCPortScanView::Dump(CDumpContext&dc){}CPortScanDoc*CPortScanView::GetDocument()//non-debugversionis{return(CPortScanDoc*)m_pDocument;}#endif//CPortScanViewmessage{HBRUSHhbr=CFormView::OnCtlColor(pDC,pWnd,//breakstatementmustbeignored:{casecasecasereturnstatic_cast<HBRUSH>(m_pBrush-}//TODO:ReturnadifferentbrushifthedefaultisnotdesiredreturnCFormView::OnCtlColor(pDC,pWnd,nCtlColor);}BOOLCPortScanView::AddColumn(LPCTSTRstrItem,intnItem,intnSubItem,intnMask,intnFmt){lvc.mask=nMask;lvc.fmt=nFmt;lvc.pszText=(LPTSTR)lvc.cx=m_cResult.GetStringWidth(lvc.pszText)+if(nMask&{if(nSubItem!=-1)lvc.iSubItem=nSubItem;}

lvc.iSubItem=return}BOOLCPortScanView::AddItem(intnItem,intnSubItem,LPCTSTRstrItem,int{LV_ITEMlvItem;lvItem.mask=LVIF_TEXT;lvItem.iItem=nItem;lvItem.iSubItem=nSubItem;lvItem.pszText=(LPTSTR)if(nImageIndex!=-{lvItem.mask|=LVIF_IMAGE;lvItem.iImage|=LVIF_IMAGE;}if(nSubItem==returnreturn}voidCPortScanView::AddHeader(LPTSTR{ifm_pColumns-}void{intnIndex=POSITIONpos=m_pColumns->GetHeadPosition();while(pos){CStringhdr=(CString)m_pColumns->GetNext(pos);}}{AddHeader(_T("IP地址"));}void{m_bSinglePort=TRUE;}void{m_bSinglePort=FALSE;}void{CStringbtnTxt,IP;UINTnSinglePort;BYTEf1,f2,f3,f4;TCHARtemp[10]="\0";POSITIONp=m_pStatusList->GetHeadPosition();while(p){POSITIONtemp=ifdelete}if{MB_OK|}if(m_cIP.GetAddress(f1,f2,f3,f4)<{_T("InvalidIPaddress"),MB_OK|MB_ICONEXCLAMATION);}//进行IP地址转化IP_itoa(f1,temp,10);IP+=_T('.');IP+=_itoa(f2,temp,10);IP+=_T('.');IP+=_itoa(f3,temp,10);IP+=_T('.');IP+=if(m_bSinglePort){}{

CStringport;m_minPort=m_maxPort=nSinglePort=CStringport1,port2;m_minPort=atoi(port1);m_maxPort=}if(!m_bSinglePort&&m_maxPort<{MB_OK|}UINTm_nMaxAttempts=for(m_nCounter=m_minPort;m_nCounter<=m_maxPort;{BOOLbIsOpen=UINTnAttempt=while(nAttempt<=m_nMaxAttempts&&{TCHARCStringstr_T("连接端口#ifdef_UNICODEstr+=_itow(m_nCounter,temp,10);str+=itoa(m_nCounter,temp,10);str_T("IP地址=");str+=IP;str+=_T(",Attempt=");#ifdef_UNICODEstr+=_itow(nAttempt,temp,10);str+=itoa(nAttempt,temp,10);bIsOpen=if(bIsOpen){pNode->bStatus=1;//openpNode->nAttempts=nAttempt;}}if(!bIsOpen){pNode->bStatus=0;//关闭状态pNode->nAttemptsnAttempt-1;}MSGif{}}UINTnIndex0;POSITIONpos=m_pStatusList-while(pos){if(pNode-{}{}

}}{CTheSocket*pSocket;pSocket=newCTheSocket;{deletepSocket;pSocket=NULL;returnFALSE;}while(!pSocket->Connect(IP{deletepSocket;pSocket=NULL;returnFALSE;}deletepSocket;returnTRUE;}void{m_nCounter=m_maxPort+1;}void{CFileDialog*pDlg=newOFN_OVERWRITEPROMPT|_T("Scannedportsfilesif(pDlg->DoModal()=={int _open(pDlg->GetPathName(),_O_BINARY _O_CREAT_O_TRUNC|if(nHandle==-{MessageBox(_T("UnabletoopenoutputfiletoMB_OK|deletepDlg;}POSITIONpos=m_pStatusList->GetHeadPosition();while(pos){CStringbuffer=pNode->IPAddress;buffer+=buffer+=_T(',');if(pNode-buffer+=buffer+=buffer+=_T("\r\n\0");if(retVal!={MessageBox(_T("Anerroroccuredwhilewriting_T("Error"),MB_OK|deletepDlg;}}}delete}#if!defined(AFX_PORTSCANVIEW_H4D7B6B4D_FDBC_11D4_B48A_F589D689A532INCLUDED_)AFX_PORTSCANVIEW_H4D7B6B4D_FDBC_11D4_B48A_F589D689A532I#if_MSC_VER>#pragma#endif//_MSC_VER>classCMainFrame;//Thisdatastructureregistersthestatusesofscannedports:typedefstruct{intTCHARport[5];BOOLbStatus;//1=open,0=classCPortScanView:public{//MaximumattemptstoconnectasocketUINTm_nMaxAttempts;//createfromserializationonlyCMainFrame*m_parent;//Showstheheadersofmembervariablem_cResult(Seebelow)voidShowHeaders(void);//Addssomenewheaderstom_cResult.voidAddHeader(LPTSTRhdr);//AddsanewitemtoAddItem(intnItem,intnSubItem,LPCTSTRstrItem,intnImageIndex=-1);//Addsanewcolumntom_cResultLPCTSTRstrItem,intnItem,intnSubItem=-intnMask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|intnFmt=LVCFMT_LEFT);enum{IDD=IDD_PORTSCAN_FORM //Numberofattemptstocheckwhetherornotaportisopenorclose m_cResult;//TheresultcomesonscreenbythisobjectCButtonm_cBtnScan;CIPAddressCtrlm_cIP;//DestinationIPaddressisgotfromthisControl //Upperrangeofscanningports //Lowerrangeofscanningports m_cSinglePort;//Asingleportnumbertobescanned//AttributesCPortScanDoc*////ClassWizardgeneratedvirtualfunctionvirtualvoidDoDataExchange(CDataExchange*pDX); //DDX/DDVsupportvirtualvoidOnInitialUpdate();//calledfirsttimeafterconstruct//Implementationvirtual~CPortScanView();#ifdefvirtualvoidAssertValid()virtualvoidDump(CDumpContext&dc)co

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论