JavaScript Obtenha informações de hardware e sistema do computador cliente
Através da WMI para obter informações de hardware e sistema do computador cliente:
Copie o código do código da seguinte forma:
função getsysinfo () {
var local = new ActivexObject ("wbemscripting.swbemlocator");
var Service = local.ConnectServer (".");
// Informações da CPU
var cpu = new Enumerator (Service.execQuery ("Selecione * FROM WIN32_Processor"). Item () ;;);
var cputype = cpu.name, hostName = cpu.systemName;
// Informações de memória
var memória = new Enumerator (Service.execQuery ("Selecione * de Win32_PhysicalMemory");););
For (var mem = [], i = 0; .Itemm () .Speed}
// Informações do sistema
var System = new Enumerator (Service.execQuery ("Selecione * FROM WIN32_COMPUTERSYSTEM"). Item ();
Var PhysicMencap = Math.ceil (System.TotalphysicalMemory/1024/1024), CURUSER = System.username, cpucount = System.NumberProcessors
Return {cputype: cputype, cpucount: cpucount, hostName: hostName, Curusser: Curusser, Memcap: PhysicMencap, MEM: MEM}
}
A implementação do código inclui principalmente estas peças:
Primeiro passe o novo ActiveXObject ("wbemscripting.swbemlocator");
Por local.ConnectServer (".");
Você também pode acessar outros computadores).
Através do serviço.execQuery ("Selecione * FROM WIN32_Processor"), uma instrução SQL semelhante (de fato, as informações do sistema também são armazenadas em um arquivo semelhante ao banco de dados nos cálculos) para obter o conjunto de registros de que precisamos.
Crie um objeto enumerado através do novo enumer e você pode atravessar as informações abaixo.
Nota: A premissa de corrida é modificar as configurações de segurança do navegador, "permitindo que o ActiveX, que não é marcado como seguro".
A operação do script ".
Aqui estão as principais informações dos usuários de CPU, memória e sistema.
Para mais informações. A classe de informações comuns está listada abaixo:
Win32_Processor // CPU Processor
Win32_physicalMemory // Memória física
Win32_keyboard // teclado
Win32_PoinTingDevice // Ponto de entrada de dispositivo, como mouse
Win32_diskdrive // drive Drive Drive
Win32_cdromdrive // CD Drive
Win32_baseboard // placa -mãe
Win32_bios // chip de bios
Win32_parallelport //
Win32_Serialport // Porta serial
Win32_SoundDevice // Configurações multimídia
Win32_USBController // USB Controller
Win32_networkadapter // adaptador de rede
Win32_NetworkAdapterConfiguration // Configurações do adaptador de rede
Win32_printer // impressora
Win32_PrinterConfiguration // Configurações da impressora
Win32_printjob // Tarefa da impressora
Win32_tcpipprinterport // Porta de impressora
Win32_potsmodem // modem
Win32_potsmodemtoserialport // Porta modem
Win32_DeskTopMonitor // Display
Win32_VideoController // Detalhes da placa gráfica.
Win32_videosettings // O modo de exibição suportado pela placa gráfica.
Win32_TimeZone // Fuso horário
Win32_SystemDriver // Driver
Win32_DiskPartition // Partição de disco
Win32_LogicalDisk // Disco lógico
Win32_LogicalMemoryConfiguration // Configuração de memória lógica
Win32_PageFile // Página do sistema Informações
Win32_PageFileSetting // Configurações de arquivo de página
Win32_BootConfiguration // Configuração de inicialização do sistema
Win32_operatingsystem // Informações do sistema operacional
Win32_startupCommand // o programa de inicialização automática do sistema
Win32_Service // Serviço de instalação do sistema
Win32_Group // Grupo de Gerenciamento do Sistema
Win32_groupuser // Número da conta do grupo do sistema
Win32_UserAccount // Conta de usuário
Processo de sistema Win32_Process //
Win32_thread // Thread System
Win32_Share // Compartilhar
Win32_networkclient // o cliente online instalado
Win32_NetworkProtocol // O protocolo de rede instalado
Para obter informações completas e listas detalhadas da classe WMI Win32, consulte o MSDN:
http://msdn2.microsoft.com/en-s/library/aa394084 (vs.85) .aspx
Exemplo:
Copie o código do código da seguinte forma:
Função button1_onClick () {// Informações da CPU
var local = new ActivexObject ("wbemscripting.swbemlocator");
var Service = local.ConnectServer (".");
Var Properties = Service.execQuery ("Selecione * de Win32_Processor");
var e = novo enumerador (propriedades);
document.write ("<tabela borda = 1>");
para (;! e.atend (); e.movenext ())
{{
var p = E.Item ();
document.write ("<ter>");
document.write ("<td>" + p.caption + "</td>");
document.write (<td> " + p.deviceId +" </td> ");
document.write ("<td>" " + p.name +" </td> ");
document.write ("<td>" " + p.cpustatus +" </td> ");
document.write ("<td>" " + p.Avilability +" </td> ");
document.write ("<td>" " + p.level +" </td> ");
document.write ("<td>" " + p.processorId +" </td> ");
document.write ("<td>" " + p.systemName +" </td> ");
document.write ("<td>" + p.processorType + "</td>");
document.write ("</tr>);
}
document.write ("</ table>");
}
Função button2_onClick () {// informações de CD-ROM
var local = new ActivexObject ("wbemscripting.swbemlocator");
var Service = local.ConnectServer (".");
Var Properties = Service.execQuery ("Selecione * de Win32_cdromdrive");
var e = novo enumerador (propriedades);
document.write ("<tabela borda = 1>");
para (;! e.atend (); e.movenext ())
{{
var p = E.Item ();
document.write ("<ter>");
document.write ("<td>" + p.caption + "</td>");
document.write ("<td>" " + p.Descript +" </td> ");
document.write ("<td>" + p.Drive + "</td>");
document.write ("<td>" " + p.status +" </td> ");
document.write ("<td>" " + p.medialOaded +" </td> ");
document.write ("</tr>);
}
document.write ("</ table>");
}
Função button3_onClick () {// Informações do teclado
var local = new ActivexObject ("wbemscripting.swbemlocator");
var Service = local.ConnectServer (".");
Var Properties = Service.execQuery ("Selecione * FROM WIN32_KEYBOARD");
var e = novo enumerador (propriedades);
document.write ("<tabela borda = 1>");
para (;! e.atend (); e.movenext ())
{{
var p = E.Item ();
document.write ("<ter>");
document.write ("<td>" " + p.Descript +" </td> ");
document.write ("<td>" " + p.name +" </td> ");
document.write ("<td>" " + p.status +" </td> ");
document.write ("</tr>);
}
document.write ("</ table>");
}
Função button4_onClick () {// Informações da placa -mãe
var local = new ActivexObject ("wbemscripting.swbemlocator");
var Service = local.ConnectServer (".");
Var Properties = Service.execQuery ("Selecione * de Win32_baseboard");
var e = novo enumerador (propriedades);
document.write ("<tabela borda = 1>");
para (;! e.atend (); e.movenext ())
{{
var p = E.Item ();
document.write ("<ter>");
document.write ("<td>" " + p.hostingboard +" </td> ");
document.write ("<td>" " + p.Manufacturer +" </td> ");
document.write ("<td>" + P.Poweredon + "</td>");
document.write ("<td>" + p.product + "</td>");
document.write ("<td>" " + P. P. P. P." </td> ");
document.write ("<td>" " + p.version +" </td> ");
document.write ("</tr>);
}
document.write ("</ table>");
}
Além disso, você também pode obter as informações relevantes das seguintes maneiras:
Copie o código do código da seguinte forma:
<html> <head> <title> wmi script html </title>
<Meta http-equiv = content-type content = "text/html; charset = gb2312">
<Script Language = JScript Event = "OnCompleted (HRESULT, PERROROBJED, PASYNCCONTEXT)" para = foo>
document.forms [0] .txtMacadr.Value = UNESCAPE (MACADDR);
document.forms [0] .txtipaddr.value = UNESCAPE (ipaddr);
document.forms [0] .txtdnsname.value = UNESCAPE (SDNSNAME);
//document.formbar.submit ();
</Script>
<Script Language = JScript Event = ONOBJECTREADY (Objobject, objasyncContext) para = foo>
if (objobject.ipeNabled! = null && objobject.ipeNabled! = "indefinido" && objobject.ipeNabled == true)
{{
If (objobject.macaddress! = Null && objobject.macaddress! = "Indefinido")
Macaddr = object.macaddress;
if (objobject.ipeNabled && objobject.ipaddress (0)! = null && objobject.ipadddress (0)! = "indefinido")
Ipaddr = object.ipaddress (0);
if (objobject.dnshostname! = null && objobject.dnshostname! = "indefinido")
sdnsname = object.dnshostName;
}
</Script>
<Meta content = "mshtml 6.00.2800.1106" nome = gerador> </ad Head>
<Body>
<Object ID = Local ClassID = CLSID: 76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT>
<Object ID = Foo ClassID = CLSID: 75718C9A-F029-11D1-A1AC-004FB6C223>
<idioma de script = jscript>
var Service = local.ConnectServer ();
var macaddr;
var ipaddr;
var domainddr;
var sdnsName;
Service.Security_.IMPERSONATIONLEVEL = 3;
Service.InstancesOfasync (Foo, 'Win32_NetworkAdapterConfiguration');
</Script>
<Form id = "formFoo" name = "formbar" action = "index.do" method = "post"> <valor de entrada = "00-11-11-b4-52-sef" name = "txtMacaddr"> <entrada Value = "210.42.38.50" name = "txtipaddr"> <insput value = "zhupan" name = "txtdnsname"> </body> </html>
Copie o código do código da seguinte forma:
De fato, o mais importante é usar dois ActiveX:
<Object ID = Local ClassID = CLSID: 76A64158-CB41-11D1-8B02-00600806D9B6 VIEWASTEXT>
<Object ID = Foo ClassID = CLSID: 75718C9A-F029-11D1-A1AC-004FB6C223>
No entanto, esses dois ActiveX são criados sistematicamente, sem precisar baixar ou registrar.
O próximo trabalho é interagir com o ActiveX com scripts
<html>
<head>
<Script Language = "Javascript" type = "text/javascript">
função getCode () {
var local = new ActivexObject ("wbemscripting.swbemlocator");
var Service = local.ConnectServer (".");
Var Properties = Service.execQuery ("Selecione * de Win32_NetworkAdapterConfiguration onde ipenabld = true");
var e = novo enumerador (propriedades);
document.write ("<tabela borda = 1>");
para (;! E.Atend (); E.MoveNext ()) {
var p = E.Item ();
//If.ip.ipadddress (0)! = NULL && p.ipaddress (0)! ) .0.1 ") {{
document.write ("<ter>");
document.write ("<td>" " + p.Servicename +" </td> ");
document.write ("<td>" " + p.macaddress +" </td> ");
document.write ("<td>" " + p.ipaddress (0) +" </td> ");
document.write ("</tr>);
// Quebrar;
//}
}
document.write ("</ table>");
}
</script>
</head>
<Body>
<button id = "test" value = "test" onclick = "getCode ()"> test </botão>
</Body>
</html>
Classe WIN32_NETWORKADAPTERCONFIGURAÇÃO: CIM_SETTING
{{
Boolean ArpalwaysSourcerote;
Arpuseethersnap booleano;
Legenda da string;
string databasepath;
DeadgwDeteCtectEnabled booleano;
string defaultipgateway [];
Uint8 defaulttos;
Uint8 defaultTl;
descrição da sequência;
Boolean dhcpenabled;
DATETIME DHCPLEASEXIRES;
DATETIME DHCPLEASEOBINE;
string dhcpServer;
string dnsDomain;
string dnsDomaInSuffixSearchordr [];
Boolean dnsenabledforwinsrsolution;
string dnsshostName;
string dnsserverversearchOrder [];
DomaiNAInSRegistratinabled Boolean;
UINT32 ForwardBuffermemory;
Boolean fulldnSregistrationNabled;
uint16 gatewaycostmétrico [];
Uint8 igmplevel;
Índice UINT32;
UINT32 interfaceIndex;
string ipaddress [];
UINT32 ipConnectionMetric;
BOOLEAN iPEnabled;
BOOLEAN IPFilterSecurityEnabled;
Boolean iPportSecurityedabled;
String iPsecperMitipprotocols [];
string iPsecPerMittCPorts [];
string iPsecPerMitudPorts [];
string ipsubnet [];
IPUSEZEROBROADCOL BOOLEANS;
string ipxaddress;
Ipxenabled booleano;
Uint32 ipxfRameType [];
Uint32 ipxmediaType;
string ipxNetworkNumber [];
string ipxvirtualNetNumber;
UINT32 KeepaliveInterval;
UINT32 KeepAliveTime;
MacAdress de string;
UINT32 MTU;
Uint32 numforwardpackets;
Boolean pmtubhdetectenabled;
PMTudescobertos booleanos;
serviço de string;
String SettingId;
UINT32 TCPIPNETBIOSOPTIONS;
UINT32 TCPMAXCONNECTRETRANSMISIÇÕES;
Uint32 tcpmaxdataretransmisões;
Uint32 tcpnumConnections;
TCPUSERFC12222GENTPOINTER BOOLEAN;
Uint16 tcpwindowsize;
Boolean WinsenablelMhostSlookUp;
string winshostlookupfile;
String winsPrimaryServer;
String winscopeid;
String winssecondaryserver;
};