Imports System.Management
Imports System.Data.SqlClient
Imports System.Net
Imports System.Net.Mail
Imports System.IO
Partial Class any_kind_refer_pingIP
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Call Ping("C1012849807") 'ping 刷卡機
End Sub
Private Sub Ping(ByVal ip As String)
Dim o As Object, p As Object, s As Object
Dim i As Integer
Dim PtcAddr As String
Dim Pingtimes As Integer = 0
o = GetObject("winmgmts:{impersonationLevel=impersonate}")
For i = 0 To 3
p = o.ExecQuery("Select * From Win32_PingStatus Where Address = '" & ip & "'")
For Each s In p
If (s.StatusCode) <> Nothing Or s.StatusCode <> 0 Then
'Ping = "Computer " & ip & " is not reachable"
Pingtimes -= 1
Else '
PtcAddr = s.ProtocolAddress
'Ping = Ping() & vbCrLf & _
' "Bytes=" & s.BufferSize & " " & _
' "Time=" & s.ResponseTime & "ms " & _
' "TTL=" & s.ResponseTimeToLive
Pingtimes += 1
End If
Next
Next
If Pingtimes >= 1 Then '代表電腦有開機
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "javascript", "window.parent.frames(3).location='work.aspx'", True)
ElseIf Pingtimes <= 0 Then '代表電腦無開機
Page.ClientScript.RegisterClientScriptBlock(Me.GetType(), "javascript", "window.parent.frames(3).location='errorweb.aspx'", True)
End If
'Ping = "Pinging " & ip & _
' IIf(ip = PtcAddr, "", " [" & PtcAddr & "] ") & vbCrLf & Ping
End Sub
End Class
call ping.bat C1012849807
@echo off ping %1 > NUL if %ERRORLEVEL% EQU 0 explorer "work.aspx" else explorer "errorweb.aspx"
using Microsoft.VisualBasic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.Management;
using System.Data.SqlClient;
using System.Net;
using System.Net.Mail;
using System.IO;
partial class any_kind_refer_pingIP : System.Web.UI.Page
{Protected void Page_Load(object sender, System.EventArgs e)
{
Ping("C1012849807");//ping 刷卡機
}
private void Ping(string ip)
{
object o = null;
object p = null;
object s = null;
int i = 0;
string PtcAddr = null;
int Pingtimes = 0;
o = Interaction.GetObject("winmgmts:{impersonationLevel=impersonate}");
for (i = 0; i <= 3; i++) {
p = o.ExecQuery("Select * From Win32_PingStatus Where Address = '" + ip + "'");
foreach (object s_loopVariable in p) {
s = s_loopVariable;
if ((s.StatusCode) != null | s.StatusCode != 0) {
//Ping = "Computer " & ip & " is not reachable"
Pingtimes -= 1;
//
} else {
PtcAddr = s.ProtocolAddress;
//Ping = Ping() & vbCrLf & _
// "Bytes=" & s.BufferSize & " " & _
// "Time=" & s.ResponseTime & "ms " & _
// "TTL=" & s.ResponseTimeToLive
Pingtimes += 1;
}
}
}
//代表電腦有開機
if (Pingtimes >= 1) {
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "javascript", "window.parent.frames(3).location='work.aspx'", true);
//代表電腦無開機
} else if (Pingtimes <= 0) {
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "javascript", "window.parent.frames(3).location='errorweb.aspx'", true);
}
//Ping = "Pinging " & ip & _
// IIf(ip = PtcAddr, "", " [" & PtcAddr & "] ") & vbCrLf & Ping
}
public any_kind_refer_pingIP()
{
Load += Page_Load;
}
//放在討論字數有限制 這裡再放一次