⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cscanportdlg.cpp

📁 端口扫描工具
💻 CPP
📖 第 1 页 / 共 2 页
字号:
		if( minPort<=0 || minPort>65566||maxPort<=0||maxPort>65566 )     
		{	
		   	MessageBox(_T("Please specify the start's or stop's Port !"),_T("Invalid	Port address!"),MB_OK|MB_ICONEXCLAMATION);
			m_cBtnStop.EnableWindow(FALSE);
		    m_cBtnScan.EnableWindow();
			m_cPortFrom.SetWindowText((CString)_T(" "));
			m_cPortTo.SetWindowText((CString)_T(" "));
			return;
		}
	 }

	 if(!m_bSinglePort&&maxPort<minPort)
	 {
		 	MessageBox(_T("The maximun range cannot be less than the minimun one!"),_T("Caution!"),MB_OK|MB_ICONEXCLAMATION);
			m_cBtnStop.EnableWindow(FALSE);
			m_cBtnScan.EnableWindow();
			m_cPortFrom.SetWindowText((CString)_T(" "));
			m_cPortTo.SetWindowText((CString)_T(" "));
			return;
	 }
     m_cProgress.StepIt();
	
	 UINT nMaxAttempts=GetDlgItemInt(IDC_EDIT_ATTEMPTS);
	 if(nMaxAttempts<=0||nMaxAttempts>65566)     
	  {	
		   	MessageBox(_T("Please specify the Attempts !"),_T("Invalid Attempts!"),MB_OK|MB_ICONEXCLAMATION);
		    m_cBtnStop.EnableWindow(FALSE);
			m_cBtnScan.EnableWindow();
			m_cAttempts.SetWindowText((CString)_T(" "));
			return;
	  }
	 m_bStart=TRUE;

	if( (ef1>=sf1&&ef2>=sf2&&ef3>=sf3&&ef4>=sf4)||(ef1>=sf1&&ef2>=sf2&&ef3>sf3)||(ef1>=sf1&&ef2>sf2)||(ef1>sf1)) 
	{  }
	else 
		MessageBox("The start IP can not less than The end IP!","Cautio",MB_OK|MB_ICONEXCLAMATION);
	
	UINT  K1=sf1,K2=sf2,K3=sf3,K4=sf4;
	while( (ef1>=K1&&ef2>=K2&&ef3>=K3&&ef4>=K4)||(ef1>=K1&&ef2>=K2&&ef3>K3)||(ef1>=K1&&ef2>sf2)||(ef1>K1)) 
	{
		IP=GetIPAddress(K1,K2,K3,K4);
		for(nCounter=minPort;nCounter<=maxPort;nCounter++)
		{
			BOOL bIsOpen=FALSE;
			UINT nAttempt=1;
			CString string1,string2;
			while(nAttempt<=nMaxAttempts&&!bIsOpen)
			{   
				m_cProgress.SetRange32(0,maxPort-minPort+1);
				TCHAR temp[10]="\0";
				CString str=_T("Trying port#");
#ifdef _UNICODE
				str+=_itow(nCounter,temp,10);
#else  
				str+=itoa(nCounter,temp,10);
#endif
				str+=_T(",IP Address=");
				str+=IP;
				str+=_T(",Attempt=");
#ifdef _UNICODE
				str+=_itow(nAttempt,temp,10);
#else  
				str+=itoa(nAttempt,temp,10);
#endif
				m_cc.SetWindowText(str);
				bIsOpen=TestConnection(IP,nCounter);
				 str.Empty();
			
				if(bIsOpen)
				{   
					TreeCtrlItem.hInsertAfter=TVI_LAST;
					TreeCtrlItem.item.mask=TVIF_TEXT|TVIF_PARAM;
					//第一级
					TreeCtrlItem. hParent = TVI_ROOT;   //父级为根部
					CString    strIP=IP;
					TreeCtrlItem.item.pszText=strIP.GetBuffer(30);
					TreeCtrlItem.item.lParam=1;    //对于根目录,设置为1
					hTreeItem=m_cTreeResult.InsertItem(&TreeCtrlItem);
					//第二级
					HTREEITEM         hTreeItem1;
					TreeCtrlItem. hParent =hTreeItem;
					TreeCtrlItem.item.lParam=10;     //对于子目录,设置为10
					strcpy(TreeCtrlItem.item.pszText,_itoa(nCounter,temp,10));
					 hTreeItem1=m_cTreeResult.InsertItem(&TreeCtrlItem);
					//第三级
					TreeCtrlItem. hParent = hTreeItem1;
					TreeCtrlItem.item.lParam=20;     //对于子目录,设置为20
					strcpy(TreeCtrlItem.item.pszText,_T("Open"));
					m_cTreeResult.InsertItem(&TreeCtrlItem);
				}
				nAttempt++;
			}
			MSG   message;
			if(::PeekMessage(&message,NULL,0,0,PM_REMOVE))
			{  
				::TranslateMessage(&message);
				::DispatchMessage(&message);
			}
		}
        
		if(++K4>255){
						K4=0;	
						++K3;
					}
		if(K3>255){
					K3=0;
					++K2;
					}
		if(K2>255){
					K2=0;
					K1++;
					}
	}
	 	CTime  timee=CTime::GetCurrentTime();
		int nhe=timee.GetHour();
		int nme=timee.GetMinute();
		int nse=timee.GetSecond();
		char  tempe[10]=_T("\0");
		CString stre;
               //  当小时小于10时,在它的前面加上0
		if(nhe<10)
		{
			stre+=_T("0");
		    stre+=itoa(nhe,tempe,10);
		}
		else
		{
			stre+=itoa(nhe,tempe,10);
		}
		stre+=":";
        	// //  当分小于10时,在它的前面加上0
		if(nme<10)
		{
			stre+=_T("0");
		  stre+=itoa(nme,tempe,10);
		}
		else
		{
			stre+=itoa(nme,tempe,10);
		}
		stre+=":";
		//   当秒小于10时,在它的前面加上0
		if(nse<10)
		{
			stre+=_T("0");
		   stre+=itoa(nse,tempe,10);
		}
		else
		{
			stre+=itoa(nse,tempe,10);
		}
		SetDlgItemText(IDC_STATIC_END,stre);
		m_cProgress.SetPos(0);
		m_cc.SetWindowText((CString)_T("Ready"));
        m_cBtnStop.EnableWindow();
	    m_cBtnScan.EnableWindow();
        int itotal=(nhe-nhs)*3600+(nme-nms)*60+nse-nss;
	    char  tempi[10]=_T("\0");
		CString  stri=itoa(itotal,tempi,10);
        stri+="s";
	    SetDlgItemText(IDC_STATIC_TOTAL,stri);

}





void CCScanPortDlg::OnRadioSingleport() 
{
	// TODO: Add your control notification handler code here
         m_bSinglePort=TRUE;
		 m_cPortFrom.EnableWindow(FALSE);
		 m_cPortTo.EnableWindow(FALSE);
		 m_cSinglePort.EnableWindow(TRUE);
	     m_cAttempts.EnableWindow(TRUE);
		 m_cBtnStop.EnableWindow(TRUE);
		 m_cBtnScan.EnableWindow(TRUE);
		 m_cAttempts.SetWindowText((CString)_T(" "));
		 m_cPortFrom.SetWindowText((CString)_T(" "));
		 m_cPortTo.SetWindowText((CString)_T(" "));
		 SetDlgItemText(IDC_STATIC_START,"开始时间");
		 SetDlgItemText(IDC_STATIC_TO,"To");
         SetDlgItemText(IDC_STATIC_END,"结束时间");
		 SetDlgItemText(IDC_STATIC_TOTAL,"总的扫描时间");
}

void CCScanPortDlg::OnRadioRangeport() 
{
	// TODO: Add your control notification handler code here
	    m_bSinglePort=FALSE;
		m_cPortFrom.EnableWindow(TRUE);
		m_cPortTo.EnableWindow(TRUE);
		m_cSinglePort.EnableWindow(FALSE);
		m_cAttempts.EnableWindow(TRUE);
		m_cBtnStop.EnableWindow(TRUE);
	    m_cBtnScan.EnableWindow(TRUE);
		m_cAttempts.SetWindowText((CString)_T(" "));
		m_cSinglePort.SetWindowText((CString)_T(" "));
		SetDlgItemText(IDC_STATIC_START,"开始时间");
		SetDlgItemText(IDC_STATIC_TO,"To");
        SetDlgItemText(IDC_STATIC_END,"结束时间");
		SetDlgItemText(IDC_STATIC_TOTAL,"总的扫描时间");
}



void CCScanPortDlg::OnButtonStop() 
{
	// TODO: Add your control notification handler code here
	if(!m_bStart)
	{
		MessageBox(_T("The scanning does not start ! ?"),"Caution",MB_OK|MB_ICONEXCLAMATION);
		return;
	}
    if( MessageBox( _T("Do you want to be out this programme?"),"Caution",MB_YESNO|MB_ICONEXCLAMATION )==IDYES)
	{
		exit(0);
	}   
}

void CCScanPortDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	MessageBox( _T("You have been out this programme?"),"Caution",MB_OK);
}

void CAboutDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	exit(0);
	CDialog::OnClose();
}


void CCScanPortDlg::OnOpen() 
{
	// TODO: Add your command handler code here
		OnButtonScan();
	
}

void CCScanPortDlg::OnExit() 
{
	// TODO: Add your command handler code here
	CCScanPortDlg::OnDestroy();
	exit(0);
}

void CCScanPortDlg::OnHelp() 
{
	// TODO: Add your command handler code here
	HELPDialog  help;
	if(help.DoModal()==IDOK)
	{
         MessageBox( _T("You have been out HELP!"),"Caution",MB_OK);
		 return;
	}
	else  return;
	
}

void CCScanPortDlg::OnSelchangedTreeResult(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR;
	// TODO: Add your control notification handler code here
	CString m_CurPath;
    CString  temp;
    HTREEITEM  CurItem=m_cTreeResult.GetSelectedItem();
    TV_ITEM  TreeCtrlItem;
    TreeCtrlItem. hItem=CurItem;
    m_cTreeResult.GetItem(&TreeCtrlItem);
    temp=m_cTreeResult.GetItemText(m_cTreeResult.GetSelectedItem());


     long   CurlPraram=TreeCtrlItem.lParam;
     // 当前的条目号
 
	if(CurlPraram!=1)
	{

		if(CurlPraram!=10)
		{
				HTREEITEM   htempItem=m_cTreeResult.GetParentItem(m_cTreeResult.GetSelectedItem()) ;
                m_vport=m_cTreeResult.GetItemText(htempItem);
				TreeCtrlItem. hItem=m_cTreeResult.GetParentItem(htempItem);
				m_cTreeResult.GetItem(&TreeCtrlItem);
				CurItem=TreeCtrlItem. hItem;
				m_vIP=m_cTreeResult.GetItemText(CurItem);
				TreeCtrlItem. hItem=m_cTreeResult.GetParentItem(htempItem);
				m_cTreeResult.GetItem(&TreeCtrlItem);
			    CurItem=TreeCtrlItem. hItem;
			
		}
		else
		{
			 TreeCtrlItem. hItem=m_cTreeResult.GetParentItem(m_cTreeResult.GetSelectedItem() );
		     m_cTreeResult.GetItem(&TreeCtrlItem);
			 CurItem=TreeCtrlItem. hItem;
			 m_vIP=m_cTreeResult.GetItemText(CurItem);
	    	 m_vport=temp;
			 
		}
	}
	else
	{
		m_vIP=temp;
		HTREEITEM  hChildItem=m_cTreeResult.GetChildItem(m_cTreeResult.GetSelectedItem());
		m_vport=m_cTreeResult.GetItemText(hChildItem);
	
	}
	UpdateData(FALSE);
	*pResult = 0;
}

void CCScanPortDlg::OnBUTTONAttack() 
{
	// TODO: Add your control notification handler code here
    UpdateData(TRUE);
	UINT  uPORT=GetDlgItemInt(IDC_EDIT_PORT);
	SOCKADDR_IN dest;
	memset(&dest,0,sizeof(dest));
	dest.sin_addr.S_un.S_addr=inet_addr(m_vIP);
	dest.sin_port=htons(uPORT);
	dest.sin_family=AF_INET;
	SOCKET hsock=socket(AF_INET,SOCK_STREAM,0);
	int i=sendto(hsock,m_context,sizeof(m_context),0,(sockaddr*)(&dest),sizeof((sockaddr*)(&dest)));
     if(i!=0)
		 {
			 MessageBox( _T("??2"),"Caution",MB_OK);
		 }
    closesocket(hsock);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -