2022年計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)端口掃描實(shí)驗(yàn)報(bào)告_第1頁(yè)
2022年計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)端口掃描實(shí)驗(yàn)報(bào)告_第2頁(yè)
2022年計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)端口掃描實(shí)驗(yàn)報(bào)告_第3頁(yè)
2022年計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)端口掃描實(shí)驗(yàn)報(bào)告_第4頁(yè)
2022年計(jì)算機(jī)網(wǎng)絡(luò)課程設(shè)計(jì)端口掃描實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩32頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

目錄TOC\o"1-4"1需求分析 31.1課程設(shè)計(jì)目的 31.2課程設(shè)計(jì)內(nèi)容 31.3課程設(shè)計(jì)要求 32概要設(shè)計(jì) 32.1原理概述 32.2運(yùn)行環(huán)境 32.3基本設(shè)計(jì)思路 32.4功能模塊設(shè)計(jì) 33詳細(xì)設(shè)計(jì) 33.1程序流程 33.2主要算法 53.3主要數(shù)據(jù)結(jié)構(gòu) 63.4主要函數(shù)說(shuō)明 64用戶使用手冊(cè) 75項(xiàng)目分析與總結(jié) 75.1項(xiàng)目分析 75.2總結(jié)與建議 8附錄A源程序代碼文件說(shuō)明 8附錄B參考文獻(xiàn) 20需求分析1.1課程設(shè)計(jì)目的加深對(duì)TCP/IP的理解,熟悉socket編程。課程設(shè)計(jì)內(nèi)容實(shí)現(xiàn)一個(gè)掃描器,使用TCPconnect進(jìn)行端口掃描,并把掃描到的結(jié)果記錄下來(lái)。課程設(shè)計(jì)要求Windows或Linux環(huán)境下,程序在單機(jī)上運(yùn)行;使用端口掃描對(duì)一臺(tái)主機(jī)進(jìn)行掃描,并顯示出結(jié)果;對(duì)一個(gè)網(wǎng)段進(jìn)行IP掃描,顯示出結(jié)果;提供友好的用戶界面。概要設(shè)計(jì)2.1原理概述TCPconnect掃描是最基本的掃描,操作系統(tǒng)提供的connect()系統(tǒng)調(diào)用,用來(lái)與每一個(gè)感興趣的目標(biāo)計(jì)算機(jī)的端口進(jìn)行連接。如果端口處于偵聽狀態(tài),那么connect()就能成功。否則,這個(gè)端口是不能用的,即沒(méi)有提供服務(wù)。2.2運(yùn)行環(huán)境Windowsxp,VC++6.02.3基本設(shè)計(jì)思路創(chuàng)建一個(gè)CSocket套接字,通過(guò)CSocket的Connect函數(shù)測(cè)試該主機(jī)的某個(gè)端口是否能夠連通,獲得該端口的打開狀態(tài)。2.4功能模塊設(shè)計(jì)(1)測(cè)試主機(jī)某個(gè)端口是否打開;(2)“掃描結(jié)果”標(biāo)題欄;(3)掃描單個(gè)或多個(gè)端口的單選按鈕;(4)“掃描”,“停止”,“保存”按鈕。3.詳細(xì)設(shè)計(jì)3.1程序流程開始掃描開始掃描初始化掃描單個(gè)端口?Tm_bSinglePort=true;m_cSinglePort.EnableWindow();m_cPortFrom.EnableWindow(false);m_cPortTo.EnableWindow(false);m_cBtnStop.EnableWindow(false);Fm_bSinglePort=false;m_cSinglePort.EnableWindow(false);m_cPortFrom.EnableWindow();m_cPortTo.EnableWindow();m_cBtnStop.EnableWindow(false);設(shè)置端口開始偵聽端口有錯(cuò)誤?顯示結(jié)果FT設(shè)置下一端口掃描結(jié)束3.2主要算法(1)測(cè)試主機(jī)某個(gè)端口是否打開的函數(shù)TestConnection():BOOLCMyDlg::TestConnection(CStringIP,UINTnPort){CSocket*pSocket; pSocket=newCSocket; ASSERT(pSocket); if(!pSocket->Create()) {deletepSocket; pSocket=NULL; returnfalse; } while(!pSocket->Connect(IP,nPort)) {deletepSocket; pSocket=NULL; returnfalse; } pSocket->Close(); deletepSocket; returntrue;}(2)響應(yīng)單選按鈕“掃描單個(gè)端口”和“掃描多個(gè)端口”的單擊消息:voidCMyDlg::OnRadio1Single(){m_bSinglePort=true; m_cSinglePort.EnableWindow(); m_cPortFrom.EnableWindow(false); m_cPortTo.EnableWindow(false); m_cBtnStop.EnableWindow(false);}voidCMyDlg::OnRadio2Range(){m_bSinglePort=false; m_cSinglePort.EnableWindow(false); m_cPortFrom.EnableWindow(); m_cPortTo.EnableWindow(); m_cBtnStop.EnableWindow(false);}(3)顯示列表框標(biāo)題欄的成員函數(shù)://增加列表框標(biāo)題欄的某一列BOOLCMyDlg::AddColumn(LPCTSTRstrItem,intnItem,intnSubItem,intnMask,intnFmt){LV_COLUMNlvc; lvc.mask=nMask; lvc.fmt=nFmt; lvc.pszText=(LPTSTR)strItem; lvc.cx=m_cResult.GetStringWidth(lvc.pszText)+25; if(nMask&LVCF_SUBITEM) {if(nSubItem!=-1) lvc.iSubItem=nSubItem; else lvc.iSubItem=nItem; } returnm_cResult.InsertColumn(nItem,&lvc);}//在列表框中加一條BOOLCMyDlg::AddItem(intnItem,intnSubItem,LPCTSTRstrItem,intnImageIndex){LV_ITEMlvItem; lvItem.mask=LVIF_TEXT; lvItem.iItem=nItem; lvItem.iSubItem=nSubItem; lvItem.pszText=(LPTSTR)strItem; if(nImageIndex!=-1) {lvItem.mask|=LVIF_IMAGE; lvItem.iImage|=LVIF_IMAGE; } if(nSubItem==0) returnm_cResult.InsertItem(&lvItem); returnm_cResult.SetItem(&lvItem);}//加一列標(biāo)題欄字符voidCMyDlg::AddHeader(LPTSTRhdr){if(m_pColumns) m_pColumns->AddTail(hdr);}//顯示列表框標(biāo)題欄voidCMyDlg::ShowHeaders(){intnIndex=0; POSITIONpos=m_pColumns->GetHeadPosition(); while(pos) {CStringhdr=(CString)m_pColumns->GetNext(pos); AddColumn(hdr,nIndex++); }}(4)“掃描”,“停止”,“保存”按鈕,見附錄程序。3.3主要數(shù)據(jù)結(jié)構(gòu)及主要函數(shù)說(shuō)明(1)測(cè)試主機(jī)某個(gè)端口是否打開——TestConnection函數(shù);(2)“掃描結(jié)果”標(biāo)題欄成員函數(shù)——AddHeader,AddColumn,ShowHeaders;在列表框中添加字符串的函數(shù)——AddItem;(3)掃描單個(gè)或多個(gè)端口的單選按鈕——OnRadioSingle()和OnRadioRange();(4)“掃描”,“停止”,“保存”按鈕——OnButton1Start(),OnButton2Stop(),OnButton3Save();4.用戶使用手冊(cè)輸入要掃描的主機(jī)IP地址,選擇“掃描單個(gè)端口”或“掃描多個(gè)端口”,若選擇前者,則輸入單個(gè)端口號(hào);若選擇后者,則輸入端口范圍。再輸入掃描次數(shù)(默認(rèn)值為1),單擊“掃描”按鈕,掃描結(jié)果列表框中將會(huì)顯示所輸入端口的掃描結(jié)果。單擊“停止”時(shí)停在那一刻的狀態(tài),并顯示已掃描的結(jié)果。單擊“保存”時(shí),可將結(jié)果保存在文本文件中。5.項(xiàng)目分析與總結(jié)5.1項(xiàng)目分析掃描單個(gè)端口的結(jié)果:掃描多個(gè)端口:通過(guò)觀察,主機(jī)IP為10.5.104.36的25號(hào)端口是打開的。5.2總結(jié)與建議通過(guò)這次實(shí)驗(yàn),加深了對(duì)端口的理解,也對(duì)socket編程有了進(jìn)一步的認(rèn)識(shí)。實(shí)驗(yàn)中遇到許多函數(shù)和定義需要上網(wǎng)查閱資料,而且調(diào)試的過(guò)程也比較困難,需要向同學(xué)請(qǐng)教。所以,今后在編程和查閱資料方面的能力有待于進(jìn)一步去提高。附錄A源程序代碼文件說(shuō)明:(1)端口掃描Dlg.h:#if!defined(AFX_DLG_H__37F5060C_6D8B_42F0_90D9_FBA754BAD52B__INCLUDED_)#defineAFX_DLG_H__37F5060C_6D8B_42F0_90D9_FBA754BAD52B__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000#include<fcntl.h>#include<sys/types.h>#include<sys/stat.h>#include<io.h>#include<afxsock.h> //掃描結(jié)果typedefstruct{intnAttempts; TCHARIPAddress[16]; TCHARport[5]; BOOLbStatus;//1=open,0=close}DATA;///////////////////////////////////////////////////////////////////////////////CMyDlgdialogclassCMyDlg:publicCDialog{//Constructionpublic: CMyDlg(CWnd*pParent=NULL); //standardconstructor//DialogData //{{AFX_DATA(CMyDlg) enum{IDD=IDD_MY_DIALOG}; CProgressCtrl m_cProgress; CListCtrl m_cResult; CIPAddressCtrl m_cIP; CEdit m_cAttempts; CEdit m_cPortTo; CEdit m_cPortFrom; CEdit m_cSinglePort; CButton m_cBtnStop; CButton m_cBtnScan; //}}AFX_DATA //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CMyDlg) protected: virtualvoidDoDataExchange(CDataExchange*pDX); //DDX/DDVsupport //}}AFX_VIRTUAL//Implementationprotected: HICONm_hIcon;BOOLTestConnection(CStringIP,UINTnPort);//測(cè)試主機(jī)某個(gè)端口是否打開 voidShowHeaders(void);//顯示列表框標(biāo)題欄 voidAddHeader(LPTSTRhdr);//增加一列標(biāo)題欄字符 AddItem(intnItem,intnSubItem,LPCTSTRstrItem,intnImageIndex=-1);//向m_cResult輸出一個(gè)結(jié)果 //向輸出結(jié)構(gòu)列表控件增加一列 BOOLAddColumn(LPCTSTRstrItem,intnItem,intnSubItem=-1, intnMask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM, intnFmt=LVCFMT_LEFT); //變量 UINTm_nMaxAttempts; //試圖連接次數(shù)的最大值 BOOLm_bSinglePort; //是否只掃描單個(gè)端口 UINTm_minPort,m_maxPort; //掃描端口的范圍 UINTm_nCounter; //端口的個(gè)數(shù) CStringList*m_pColumns; //列表框標(biāo)題欄 CPtrList*m_pStatusList;//保存掃描結(jié)果的鏈表 //Generatedmessagemapfunctions //{{AFX_MSG(CMyDlg) virtualBOOLOnInitDialog(); afx_msgvoidOnSysCommand(UINTnID,LPARAMlParam); afx_msgvoidOnPaint(); afx_msgHCURSOROnQueryDragIcon(); afx_msgvoidOnButton1Start(); afx_msgvoidOnButton2Stop(); afx_msgvoidOnButton3Save(); afx_msgvoidOnRadio1Single(); afx_msgvoidOnRadio2Range(); //}}AFX_MSG DECLARE_MESSAGE_MAP()};//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX_DLG_H__37F5060C_6D8B_42F0_90D9_FBA754BAD52B__INCLUDED_)(2)端口掃描Dlg.cpp:#include"stdafx.h"#include"端口掃描.h"#include"端口掃描Dlg.h"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialog{public: CAboutDlg();//DialogData //{{AFX_DATA(CAboutDlg) enum{IDD=IDD_ABOUTBOX}; //}}AFX_DATA //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport //}}AFX_VIRTUAL//Implementationprotected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD){ //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CAboutDlg,CDialog) //{{AFX_MSG_MAP(CAboutDlg) //Nomessagehandlers //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgdialogCMyDlg::CMyDlg(CWnd*pParent/*=NULL*/) :CDialog(CMyDlg::IDD,pParent)//在對(duì)話框的構(gòu)造函數(shù)中初始化成員變量{ //{{AFX_DATA_INIT(CMyDlg) //}}AFX_DATA_INIT //NotethatLoadIcondoesnotrequireasubsequentDestroyIconinWin32 m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME);m_pColumns=newCStringList;ASSERT(m_pColumns);m_bSinglePort=true;m_nMaxAttempts=1;m_pStatusList=newCPtrList;ASSERT(m_pStatusList);}voidCMyDlg::DoDataExchange(CDataExchange*pDX){CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMyDlg) DDX_Control(pDX,IDC_PROGRESS1,m_cProgress); DDX_Control(pDX,IDC_LIST1,m_cResult); DDX_Control(pDX,IDC_IPADDRESS1,m_cIP); DDX_Control(pDX,IDC_EDIT4_ATTEMPTS,m_cAttempts); DDX_Control(pDX,IDC_EDIT3_SINGLE_PORT_TO,m_cPortTo); DDX_Control(pDX,IDC_EDIT2_SINGLE_PORT_FROM,m_cPortFrom); DDX_Control(pDX,IDC_EDIT1_SINGLE_PORT,m_cSinglePort); DDX_Control(pDX,IDC_BUTTON2_STOP,m_cBtnStop); DDX_Control(pDX,IDC_BUTTON1_START,m_cBtnScan); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CMyDlg,CDialog) //{{AFX_MSG_MAP(CMyDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON1_START,OnButton1Start) ON_BN_CLICKED(IDC_BUTTON2_STOP,OnButton2Stop) ON_BN_CLICKED(IDC_BUTTON3_SAVE,OnButton3Save) ON_BN_CLICKED(IDC_RADIO1_SINGLE,OnRadio1Single) ON_BN_CLICKED(IDC_RADIO2_RANGE,OnRadio2Range) //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CMyDlgmessagehandlersBOOLCMyDlg::OnInitDialog()//設(shè)置按鈕的初始狀態(tài)和列表框的風(fēng)格{ CDialog::OnInitDialog(); //Add"About..."menuitemtosystemmenu. //IDM_ABOUTBOXmustbeinthesystemcommandrange. ASSERT((IDM_ABOUTBOX&0xFFF0)==IDM_ABOUTBOX); ASSERT(IDM_ABOUTBOX<0xF000); CMenu*pSysMenu=GetSystemMenu(FALSE); if(pSysMenu!=NULL) { CStringstrAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX); if(!strAboutMenu.IsEmpty()) { pSysMenu->AppendMenu(MF_SEPARATOR); pSysMenu->AppendMenu(MF_STRING,IDM_ABOUTBOX,strAboutMenu); } } //Settheiconforthisdialog.Theframeworkdoesthisautomatically //whentheapplication'smainwindowisnotadialog SetIcon(m_hIcon,TRUE); //Setbigicon SetIcon(m_hIcon,FALSE); //Setsmallicon //TODO:Addextrainitializationhere //給列表框加標(biāo)題欄AddHeader(_T("IP地址"));//加一列標(biāo)題欄字符AddHeader(_T("端口號(hào)"));AddHeader(_T("端口狀態(tài)"));AddHeader(_T("嘗試連接次數(shù)"));AddHeader(_T("標(biāo)記"));ShowHeaders();//設(shè)置掃描單個(gè)端口CheckRadioButton(IDC_RADIO1_SINGLE,IDC_RADIO2_RANGE,IDC_RADIO1_SINGLE);//設(shè)置控件的默認(rèn)狀態(tài)m_cSinglePort.EnableWindow();m_cPortFrom.EnableWindow(false);m_cPortTo.EnableWindow(false);m_cBtnStop.EnableWindow(false);m_cAttempts.SetWindowText(_T("1")); returnTRUE;//returnTRUEunlessyousetthefocustoacontrol}voidCMyDlg::OnSysCommand(UINTnID,LPARAMlParam){if((nID&0xFFF0)==IDM_ABOUTBOX) {CAboutDlgdlgAbout; dlgAbout.DoModal(); } else {CDialog::OnSysCommand(nID,lParam); }}//Ifyouaddaminimizebuttontoyourdialog,youwillneedthecodebelow//todrawtheicon.ForMFCapplicationsusingthedocument/viewmodel,//thisisautomaticallydoneforyoubytheframework.voidCMyDlg::OnPaint(){ if(IsIconic()) { CPaintDCdc(this);//devicecontextforpainting SendMessage(WM_ICONERASEBKGND,(WPARAM)dc.GetSafeHdc(),0); //Centericoninclientrectangle intcxIcon=GetSystemMetrics(SM_CXICON); intcyIcon=GetSystemMetrics(SM_CYICON); CRectrect; GetClientRect(&rect); intx=(rect.Width()-cxIcon+1)/2; inty=(rect.Height()-cyIcon+1)/2; //Drawtheicon dc.DrawIcon(x,y,m_hIcon); } else { CDialog::OnPaint(); }}//Thesystemcallsthistoobtainthecursortodisplaywhiletheuserdrags//theminimizedwindow.HCURSORCMyDlg::OnQueryDragIcon(){return(HCURSOR)m_hIcon;}voidCMyDlg::OnButton1Start()//“掃描”按鈕{//TODO:Addyourcontrolnotificationhandlercodehere CStringbtnTxt,IP; UINTnSinglePort; BYTEf1,f2,f3,f4; TCHARtemp[10]="\0";m_cProgress.SetPos(0);m_cResult.DeleteAllItems();POSITIONp=m_pStatusList->GetHeadPosition();while(p){POSITIONtemp=p;DATA*pNode=(DATA*)m_pStatusList->GetNext(p);m_pStatusList->RemoveAt(temp);if(pNode)//pNode!=nulldeletepNode;}if(m_cIP.IsBlank()){MessageBox("請(qǐng)輸入主機(jī)IP地址");return;}if(m_cIP.GetAddress(f1,f2,f3,f4)<4){MessageBox("請(qǐng)輸入有效的IP地址");return;}IP=_itoa(f1,temp,10);IP+=_T('.');IP+=_itoa(f2,temp,10);IP+=_T('.');IP+=_itoa(f3,temp,10);IP+=_T('.');IP+=_itoa(f4,temp,10);m_cBtnStop.EnableWindow();m_cBtnScan.EnableWindow(false);if(m_bSinglePort){CStringport;m_cSinglePort.GetWindowText(port);m_minPort=m_maxPort=nSinglePort=atoi(port);}else{CStringport1,port2;m_cPortFrom.GetWindowText(port1);m_cPortTo.GetWindowText(port2);m_minPort=atoi(port1);m_maxPort=atoi(port2);m_cProgress.SetRange32(0,m_maxPort-m_minPort+1);m_cProgress.SetStep(1);}if(!m_bSinglePort&&m_maxPort<m_minPort){MessageBox(_T("您輸入的端口范圍有誤,請(qǐng)重新輸入"));return;}UINTm_nMaxAttempts=GetDlgItemInt(IDC_EDIT4_ATTEMPTS);for(m_nCounter=m_minPort;m_nCounter<=m_maxPort;m_nCounter++){BOOLbIsOpen=false;UINTnAttempt=1;while(nAttempt<=m_nMaxAttempts&&!bIsOpen){TCHARtemp[10]="\0";CStringstr=_T("嘗試連接端口:");str+=itoa(m_nCounter,temp,10);str+=_T(",IP地址為=");str+=IP;str+=_T(",嘗試次數(shù)為=");str+=itoa(nAttempt,temp,10);CStatic*pStatic=(CStatic*)GetDlgItem(IDC_STATIC_STATUS);pStatic->SetWindowText(str);str.Empty();bIsOpen=TestConnection(IP,m_nCounter);if(bIsOpen){DATA*pNode=newDATA;ASSERT(pNode);strcpy(pNode->IPAddress,IP.GetBuffer(IP.GetLength()));strcpy(pNode->port,_itoa(m_nCounter,temp,10));pNode->bStatus=1;//openpNode->nAttempts=nAttempt;m_pStatusList->AddTail(pNode);}nAttempt++;}if(!bIsOpen){DATA*pNode=newDATA;ASSERT(pNode);strcpy(pNode->IPAddress,IP.GetBuffer(IP.GetLength()));strcpy(pNode->port,_itoa(m_nCounter,temp,10));pNode->bStatus=0;//closepNode->nAttempts=nAttempt-1;m_pStatusList->AddTail(pNode);}MSGmessage;if(::PeekMessage(&message,NULL,0,0,PM_REMOVE)){::TranslateMessage(&message);::DispatchMessage(&message);}m_cProgress.StepIt();}CStatic*pStatic=(CStatic*)GetDlgItem(IDC_STATIC_STATUS);pStatic->SetWindowText((CString)_T("當(dāng)前掃描狀態(tài)"));m_cBtnScan.EnableWindow();m_cBtnStop.EnableWindow(false);UINTnIndex=0;POSITIONpos=m_pStatusList->GetHeadPosition();while(pos){DATA*pNode=(DATA*)m_pStatusList->GetNext(pos);AddItem(nIndex,0,pNode->IPAddress);AddItem(nIndex,1,pNode->port);if(pNode->bStatus){AddItem(nIndex,2,_T("Open"));AddItem(nIndex,4,_T("*"));}else{AddItem(nIndex,2,_T("Close"));AddItem(nIndex,4,_T(""));}AddItem(nIndex++,3,_itoa(pNode->nAttempts,temp,10));}}voidCMyDlg::OnButton2Stop()//“停止”按鈕{//TODO:Addyourcontrolnotificationhandlercodehere m_nCounter=m_maxPort+1; m_cBtnStop.EnableWindow(false); m_cBtnScan.EnableWindow(); CStatic*pStatic=(CStatic*)GetDlgItem(IDC_STATIC_STATUS); pStatic->SetWindowText((CString)_T("當(dāng)前掃描狀態(tài)"));}voidCMyDlg::OnButton3Save()//“保存”按鈕{//TODO:Addyourcontrolnotificationhandlercodehere CFileDialog*pDlg=newCFileDialog(FALSE, _T("txt"),NULL, OFN_OVERWRITEPROMPT| OFN_EXPLORER|OFN_LONGNAMES, _T("Scannedportsfiles(*.txt)"),this); ASSERT(pDlg); if(pDlg->DoModal()==IDOK) { intnHandle,retVal; nHandle=_open(pDlg->GetPathName(),_O_BINARY|_O_CREAT|_O_TRUNC|_O_RDWR); if(nHandle==-1) { MessageBox(_T("Unabletoopenoutputfiletowrite."), _T("Error"), MB_OK|MB_ICONEXCLAMATION); deletepDlg; return; } POSITIONpos=m_pStatusList->GetHeadPosition(); while(pos) { CStringbuffer; DATA*pNode=(DATA*)m_pStatusList->GetNext(pos); buffer=pNode->IPAddress; buffer+=_T(','); buffer+=pNode->port; buffer+=_T(','); if(pNode->bStatus) buffer+=_T("Open"); else buffer+=_T("Close"); buffer+=_T("\r\n\0"); retVal=_write(nHandle, (void*)buffer.GetBuffer(buffer.GetLength()), buffer.GetLength()); if(retVal!=buffer.GetLength()) { MessageBox(_T("Anerroroccuredwhilewritingrecords."), _T("Error"),MB_OK|MB_ICONEXCLAMATION); deletepDlg; return; } buffer.Empty(); } _close(nHandle); } deletepDlg;}voidCMyDlg::OnRadio1Single(){//TODO:Addyour

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論