desktop gadget med vbscript aflæsning af DefaultGateway
Hej Der udeer der nogen af jeg der kan fortælle mig hvordan man aflæser defaultgateway i et vbscript.
jeg skal bruge det i dette script til noget SNMP
<html>
<head>
<title>SNMP</title>
<script language="VBScript">
Public STARTtime
Public enVARa
Public enVARc
strDG = "192.168.100.1" <------ Her skal der bruges en variabel der aflæser min defaultgateway
strTargetSnmpDevice = strDG 'Supply the IP address of the device to monitor
strCommunityName = "public" 'Supply the SNMP Community
strInterfaceID = 2 'Supply the ID of the Interface to monitor
set objWmiLocator = CreateObject("WbemScripting.SWbemLocator")
set objWmiServices = objWmiLocator.ConnectServer("", "root\snmp\localhost")
set objWmiNamedValueSet = CreateObject("WbemScripting.SWbemNamedValueSet")
SUB getSNMP 'Since we need DELTA information over time, this gets POLL #1 information
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", strCommunityName
Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , objWmiNamedValueSet)
For Each objInterface In colIfTable
IF objInterface.ifIndex = strInterfaceID THEN 'Only get the data from the interesting interface
enVARa = objInterface.ifInOctets
enVARc = objInterface.ifOutOctets
STARTtime = Timer() 'To get more exact length of time between the #1 and #2 SNMP polls get the time of POLL #1
END IF
Next
idTimer = window.setTimeout("PausedSection", 1000, "VBScript") 'This will pause for a while before gathering POLL #2
END SUB
SUB PausedSection 'Since we need DELTA information over time, this gets POLL #2 information
window.clearTimeout(idTimer)
objWmiNamedValueSet.Add "AgentAddress", strTargetSnmpDevice
objWmiNamedValueSet.Add "AgentReadCommunityName", strCommunityName
Set colIfTable = objWmiServices.InstancesOf("SNMP_RFC1213_MIB_ifTable", , objWmiNamedValueSet)
For Each objInterface In colIfTable
IF objInterface.ifIndex = strInterfaceID THEN 'Only get the data from the interesting interface
enVARb = objInterface.ifInOctets
enVARd = objInterface.ifOutOctets
intspeed = objInterface.ifSpeed
ENDtime = Timer() 'Time of POLL #2
END IF
Next
enVAR = Round((((enVARb - enVARa) * 8) / ((ENDtime - STARTtime) * intspeed) * 100 ),0) 'Percentage calculations for Inbound
enVARe = Round((((enVARd - enVARc) * 8) / ((ENDtime - STARTtime) * intspeed) * 100 ),0) 'Percentage calculations for Outbound
setContentText(enVAR)
setContentTextb(enVARe)
getSNMP()
END SUB
</script>
<script LANGUAGE="JavaScript1.2">
function setContentText(strB)
{
var strB;
if (strB=="Please Wait")
{
gadgetContent.innerText = strB;
} else {
gadgetContent.innerText = "Inbound: " + strB + "%";
}
}
function setContentTextb(strC)
{
var strC;
gadgetContentb.innerText = "Outbound: " + strC + "%";
indhold1.innerText = "SNMP Host :";
indhold1_1.innerText = strTargetSnmpDevice;
indhold2.innerText = "Community :";
indhold2_1.innerText = strCommunityName;
indhold3.innerText = "Interface :";
indhold3_1.innerText = strInterfaceID;
}
</script>
<link rel="stylesheet" href="layout.css" type="text/css" />
</head>
<body onload="getSNMP()">
<g:background id="imgBackground" src="black.png">
<Table>
<tr>
<td colspan="2" id="headline">SNMP</td>
</tr>
<tr>
<td colspan="2" id="gadgetContent"></td>
</tr>
<tr>
<td colspan="2" id="gadgetContentb"></td>
</tr>
<tr>
<td id="indhold1"></td><td id="indhold1_1"></td>
</tr>
<tr>
<td id="indhold2"></td><td id="indhold2_1"></td>
</tr>
<tr>
<td id="indhold3"></td><td id="indhold3_1"></td>
</tr>
</table>
<script LANGUAGE="JavaScript1.2">
setContentText("Gathering Data");
</script>
</body>
</html>