<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
for (int i = 1; i < 255; i++)
{
ScanIP(
i);
}
}
private void ScanIP(int i)
{
System.Net.NetworkInformation.Ping pingSender = new System.Net.NetworkInformation.Ping();
System.Net.NetworkInformation.PingOptions options = new System.Net.NetworkInformation.PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = " ";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
System.Net.NetworkInformation.PingReply reply = pingSender.Send(txt_IPduan.Text + "." + i.ToString(), timeout, buffer, options);
if (reply.Status == System.Net.NetworkInformation.IPStatus.Success)
{
//StringBuilder resultText = new StringBuilder();
//resultText.AppendLine("Address: " + reply.Address.ToString() + "<BR>");
//resultText.AppendLine("RoundTrip time: " + reply.RoundtripTime + "<BR>");
//resultText.AppendLine("Time to live: " + reply.Options.Ttl + "<BR>");
//resultText.AppendLine("Don't fragment: " + reply.Options.DontFragment + "<BR>");
//resultText.AppendLine("Buffer size: " + reply.Buffer.Length + "<BR>");
//lbl
_result.Text = resultText.ToString();
lbl_result.Text = lbl_result.Text + reply.Address.ToString() + " <BR>";
}
//else
// lbl_result.Text = lbl_result.Text + i.ToString() + " <BR>";
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
IPduan:<asp:TextBox ID="txt_IPduan" runat="server">192.168.85</asp:TextBox>
<asp:Button ID="btn_Scan" runat="server" OnClick="Button1_Click" Text="Scan" />
<br />
<asp:Label ID="lbl_result" runat="server" Text="Result:<BR>"></asp:Label>
<br />
</div>
</form>
</body>
</html>