- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
[C#] Hướng dẫn ping port sử dụng app Paping của google
Xin chào các bạn bài viết hôm nay mình sẽ hướng dẫn các bạn cách kiểm tra ping một port đặc biệt nào đó có mở hay không sử dụng Paping app của google tích hợp vào ứng dụng Winform C#.
[C#] Ping Special port in Winform
Vậy Paping là gì?
Paping (pronounced pah ping) là một công cụ giúp cho quản trị viên dễ dàng kiểm tra kết nối của một port nào đó và thời gian trả về kết quả ping.
Các bạn có thể download paping từ code của google hoặc download ở cuối bài viết của mình nhé.
Dưới đây là giao diện của tool Paping:
Ở hình trên các bạn thấy app đang ping đến địa chỉ ip 192.168.0.194 và kiểm tra port 554
và kết quả dưới là thời gian trả về kết quả ở cột time.
Và bài viết này mình sẽ tích hợp tool này vào app C# để kiểm tra một cách dễ dàng.
Để sử dụng paping chỉ cần gõ:
Cú pháp: paping [địa chỉ ip] -p [Port]
Dưới đây là giao diện tích hợp ping paping vào app c#:
Source code paping C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PingTool
{
public partial class Form1 : Form
{
Process process;
[DllImport("user32.dll")]
static extern int SetWindowText(IntPtr hWnd, string text);
public Form1()
{
InitializeComponent();
}
private void btn_ping_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txt_ipaddress.Text.Trim()))
{
MessageBox.Show("Bạn chưa nhập địa chỉ IP/Domain!", "Thông báo!");
return;
}
if (string.IsNullOrEmpty(txt_port.Text.Trim()))
{
MessageBox.Show("Bạn chưa nhập Port!", "Thông báo!");
return;
}
runCMD();
}
public void runCMD()
{
Properties.Settings.Default.ipaddress = txt_ipaddress.Text.Trim();
Properties.Settings.Default.port = txt_port.Text.Trim();
Properties.Settings.Default.Save();
try
{
if(process != null)
{
process.CancelErrorRead();
process.CancelOutputRead();
process.Kill();
}
}
catch (Exception)
{
}
rtbResult.Clear();
string command = $@"{Application.StartupPath}paping.exe {txt_ipaddress.Text} -p {txt_port.Text}";
process = new Process();
process.StartInfo.FileName = "cmd.exe";
if (!chkMultiWindows.Checked)
{
process.StartInfo.CreateNoWindow = true;
}
process.StartInfo.Arguments = "/c " + command;
process.StartInfo.UseShellExecute = false;
if (!chkMultiWindows.Checked)
{
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
}
process.Start();
if (!chkMultiWindows.Checked)
{
process.BeginOutputReadLine();
process.BeginErrorReadLine();
}
}
private void OutputHandler(object sender, DataReceivedEventArgs e)
{
rtbResult.BeginInvoke(new Action(() => {
var data = e.Data + Environment.NewLine;
if (data.Contains("timed out"))
{
rtbResult.AppendText(data, Color.Red);
}
else
{
rtbResult.AppendText(data);
}
rtbResult.ScrollToCaret();
}));
}
private void btn_stop_Click(object sender, EventArgs e)
{
if (process != null)
{
try
{
process.CancelErrorRead();
process.CancelOutputRead();
process.Kill();
}
catch (Exception)
{
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
txt_ipaddress.Text = Properties.Settings.Default.ipaddress;
txt_port.Text = Properties.Settings.Default.port;
chkMultiWindows.Checked = Properties.Settings.Default.multiwindows;
}
private void txt_ipaddress_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
runCMD();
}
}
private void txt_port_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
runCMD();
}
}
private void chkMultiWindows_CheckedChanged(object sender, EventArgs e)
{
Properties.Settings.Default.multiwindows = chkMultiWindows.Checked;
Properties.Settings.Default.Save();
}
}
}
Thanks for watching!