2016-08-02 31 views
2

我正在開發一個MVC中的Web應用程序。當用戶登錄到網站時,我正在獲取用戶的本地IP地址。但是現在我想要做的是掃描客戶端本地機器的開放端口列表。如何在MVC中使用C#中的本地IP地址掃描客戶端機器的開放端口?

有沒有什麼辦法可以在JavaScript或jQuery或C#中實現MVC?

+1

你會嘗試做第一這隻適用?你請教什麼文檔,教程或例子?你卡在哪裏?你的代碼的相關部分是什麼樣的,如果有的話? – Julian

回答

0
public void btnPing_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      int intCount = 0; 
      int maxip = 0; 
      richTmp.Clear(); 
      string strIP = null; 
      string machineName = string.Empty; 
      List<string> strListIp = new List<string>(); 
      List<string> txtBuffrFile = new List<string>(); 
      BufferdIp = new List<string>(); 

      for (int i = 1; i <= 30; i++) 
      { 
       System.Net.NetworkInformation.Ping p = new System.Net.NetworkInformation.Ping(); 
       lstDetails.Items.Add("System Found: " + maxip); 
       System.Net.NetworkInformation.PingReply rep = p.Send("192.168.1." + i,500); 
       if (rep.Status == System.Net.NetworkInformation.IPStatus.Success) 
       { 
        intCount++; 
        lstDetails.Items.Clear(); 
        lstDetails.Items.Add("Loading...Total(" + maxip+")"); 
        strIP = rep.Address.ToString(); 
        machineName = GetMachineNameFromIPAddress(strIP); 
        if (machineName == string.Empty || machineName == null) 
        { 
         strListIp.Add(strIP + ":-" + "Offline"); 
         BufferdIp.Add("0"); 
        } 
        else 
        { 
         strListIp.Add(strIP + ":-" + machineName+"(Online)"); 
         BufferdIp.Add(strIP); 
         txtBuffrFile.Add(strIP); 
         maxip++; 
        } 
       } 

      } 
      lstDetails.Items.Clear(); 
      foreach (var IDAddres in strListIp) 
      { 
       lstDetails.Items.Add(IDAddres); 
      } 
      for (int i = 0; i != txtBuffrFile.Count;i++) 
      { 
       richTmp.Text += txtBuffrFile.ElementAt(i) + "\n"; 
      } 
      if (MessageBox.Show("Do you want to Save This Search", "Save Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == (DialogResult.Yes)) 
      { 
       if(File.Exists (path)) 
       File.Delete(path); 
       FileStream stream = File.Create(path); 
       stream.Close(); 
       File.WriteAllText(path, richTmp.Text, Encoding.UTF8); 

      } 
      btnConnct.Enabled = true; 
     } 
     catch (Exception ex) 
     { 
      MessageBox.Show(ex.ToString()); 
     } 
    } 

我用這個在我的LAN區域ping通,但問題是當你知道IP模式和範圍:(

相關問題