private void btnGetIPAliveByIpRange_Click(object sender, EventArgs e) { DataTable dt = null; IPEnumeration IPList = new IPEnumeration("192.168.161.0", "192.168.161.255"); MvLogger.write("start process"); MvItToolBo bo = new MvItToolBo(); dt = bo.scanComputerByIpRange(new string[] { "192.168.161" }, true); MvLogger.write("end process"); Console.WriteLine(dt.Rows.Count); richTextBox1.Clear(); foreach (IPAddress ip in IPList) { bool result = MvNetworker.isPingAlive(ip); string hostName = string.Empty; string strShow = string.Empty; if (result == false) { strShow = string.Format("{0} is not alive{1}", ip.ToString(), Environment.NewLine); Console.WriteLine(strShow); richTextBox1.Text += strShow; richTextBox1.Refresh(); continue; } try { // 取host name IPHostEntry host = Dns.GetHostEntry(ip); hostName = host.HostName; strShow = string.Format("{0} {1} is alive{2}", ip.ToString(), hostName, Environment.NewLine); Console.WriteLine(strShow); richTextBox1.Text += strShow; richTextBox1.Refresh(); } catch (SocketException) { strShow = string.Format("{0} host name is not alive{1}", ip.ToString(), Environment.NewLine); Console.WriteLine(strShow); richTextBox1.Text += strShow; richTextBox1.Refresh(); } } }
/// <summary> /// 執行MvSecurityScanBo 流程 /// </summary> /// <param name="isScanFile">是否執行檔案掃描</param> /// <param name="isScanCompress">是否執行壓縮檔掃描</param> /// <param name="isBuildSummary">是否產生Local 端掃描清單</param> /// <param name="isBuildScript">是否產生power shell檔</param> /// <param name="isBuildLocalExcel">是否產生個人掃描excel資料</param> /// <param name="isBuildSummaryExcel">是否產生各PC的Summary資料</param> /// <param name="isShowInConsole">是否將結果output至Console</param> /// <param name="isOutputLog">是否輸出log檔</param> public void executeAllProcess(bool isScanFile, bool isScanCompress, bool isBuildSummary, bool isBuildScript, bool isBuildLocalExcel, bool isBuildSummaryExcel, bool isShowInConsole = false, bool isOutputLog = true) { Stopwatch watch = new Stopwatch(); MvLogger.write("run {0}.{1}", new object[] { System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name, MethodBase.GetCurrentMethod().Name }); if (Directory.Exists(DefinedParamter.workingDirectory) == false) { Directory.CreateDirectory(DefinedParamter.workingDirectory); } if (isScanFile == true) { // 1. 掃描所有實體硬碟的檔案, 並輸出檔案至指定路徑 watch.Start(); this.scanAllFilesFromPhysicalDisk(DefinedParamter.workingDirectory); watch.Stop(); Console.WriteLine("-- finished scanAllFilesFromPhysicalDisk : " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); MvLogger.write("finished scanAllFilesFromPhysicalDisk"); } if (isScanFile == true) { // 2. 掃描所有壓縮檔內容, 並將符合的detail清單, 輸出檔案至指定路徑 watch.Restart(); this.scanCompressFileContent(DefinedParamter.workingDirectory, DefinedParamter.severnZipLibrary, DefinedParamter.compressFileExtensions, DefinedParamter.mappingFileExtensions); watch.Stop(); Console.WriteLine("-- finished scanCompressFileContent : " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); MvLogger.write("finished scanCompressFileContent"); } if (isBuildSummary == true) { // 3. 整理所有summary資料, 並輸出.summary.檔案至指定路徑, 包含要copy的清單 watch.Restart(); this.buildSummaryResult(DefinedParamter.workingDirectory, DefinedParamter.compressFileExtensions, DefinedParamter.nonCompressFileExtensions, DefinedParamter.mappingFileExtensions, true); watch.Stop(); Console.WriteLine("-- finished buildSummaryResult : " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); MvLogger.write("finished buildSummaryResult"); } if (isBuildScript == true) { // 4. 依各目錄下的copylist產生powershell 檔案 watch.Restart(); this.buildCopyScript(DefinedParamter.workingDirectory); watch.Stop(); Console.WriteLine("-- finished buildCopyScript : " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); MvLogger.write("finished buildCopyScript"); } if (isBuildLocalExcel == true) { // 5. 依所有summary資料, 輸出local disk 的excel資料 watch.Restart(); this.buildLocalScannedExcel(DefinedParamter.workingDirectory); watch.Stop(); Console.WriteLine("-- finished buildLocalScannedExcel : " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); MvLogger.write("finished buildLocalScannedExcel"); } if (isBuildSummaryExcel == true) { // 6. 依所有PC資料, 輸出summary execl report watch.Restart(); this.buildSummaryExcelReport(@"D:\", @"D:\"); watch.Stop(); Console.WriteLine("-- finished buildSummaryExcelReport : " + watch.ElapsedMilliseconds.ToString() + " milliseconds"); MvLogger.write("finished buildSummaryExcelReport"); } }