Javascript obtient le matériel informatique client et les informations système
Via WMI pour obtenir le matériel informatique client et les informations système:
Copier le code du code comme suit:
function getSysInfo () {
var local = new activeXObject ("wbemscripting.swbemlocator");
var service = local.connectServer (".");
// Informations CPU
var cpu = new enumerator (service.execquery ("select * from win32_processor"). item () ;;);
var cputype = cpu.name, hostname = cpu.SystemName;
// Informations de mémoire
Var Memory = new Enumerator (Service.ExecQuery ("SELECT * FROM WIN32_PHYSICALMEMORY");););
Pour (var mem = [], i = 0 ;! memory.atend (); mémoire.MoVeNext ()) mem [i ++] = {cap: Memory.item (). .Itemm () .Speed}
// Informations système
var system = new Enumerator (Service.ExecQuery ("SELECT * FROM WIN32_COMPUTERSYSTEM"). Item ();
Var PhysicMencap = Math.Ceil (System.TotalphysicalMemory / 1024/1024), CurUser = System.Username, CPUCUNT = System.NumberProcessors
Return {Cputype: cputype, cpuccount: cpuCount, nom d'hôte: nom d'hôte, curuse: curuser, memcap: PhysicMencap, mem: mem}
}
L'implémentation du code comprend principalement ces pièces:
Passez d'abord le nouveau ActiveXObject ("wbemscripting.swbemlocator");
À travers local.connectServer (".");
Vous pouvez également accéder à d'autres ordinateurs).
Via Service.ExecQuery ("SELECT * FROM WIN32_PROCESSOR"), une instruction SQL similaire (en fait, les informations système sont également stockées dans un fichier en forme de base de données dans les calculs) pour obtenir l'ensemble d'enregistrements dont nous avons besoin.
Créez un objet énuméré via un nouvel Enumertor, et vous pouvez traverser les informations ci-dessous.
Remarque: La prémisse de l'exécution est de modifier les paramètres de sécurité du navigateur, "permettant à ActiveX, qui n'est pas marqué comme sûr".
Le fonctionnement du script ".
Voici les principales informations du CPU, de la mémoire et des utilisateurs du système.
À plus d'informations. La classe d'informations communes est répertoriée ci-dessous:
Processeur Win32_Processor // CPU
Win32_physicalmemory // mémoire physique
Win32_keyboard // clavier
Win32_pointingdevice // dispositif d'entrée ponctuel, comme la souris
Win32_diskdrive //
Win32_cdromdrive // lecteur de CD
Win32_baseboard // carte mère
Win32_bios // puce de bios
Win32_parallelport //
Win32_serialport // port série
Win32_SoundDevice // Paramètres multimédias
Win32_USBController // Contrôleur USB
Win32_networkadapter // adaptateur réseau
Win32_networkAdapterConfiguration // Paramètres de l'adaptateur réseau
Imprimante Win32_Printer //
Win32_priterconfiguration // Paramètres de l'imprimante
Win32_printJob // Tâche d'imprimante
Win32_tcpippRinterport // Port d'imprimante
Win32_potsmodem // modem
Win32_potsmodemtoserialport //
Win32_desktopmonitor // affichage
WIN32_VIDEOController // Détails de la carte graphique.
Win32_videoSettings // Le mode d'affichage pris en charge par la carte graphique.
Win32_timeZone // Fuseau horaire
Win32_SystemDriver // Driver
Win32_diskpartition // partition de disque
Win32_logicaldisk // disque logique
Win32_logicalmemoryconfiguration // configuration de mémoire logique
Win32_pagefile // Informations sur le fichier de page système
Win32_pagefileSetting // Paramètres de fichier de page
Win32_BootConfiguration // Configuration de démarrage du système
Win32_OperatingSystem // Informations sur le système d'exploitation
Win32_startupCommand // Le programme de démarrage automatique du système
Win32_Service // Service d'installation du système
Win32_Group // System Management Group
Win32_GroupUser // Numéro de compte de groupe système
Win32_UserAccount // Compte d'utilisateur
Win32_Process // Processus système
Win32_thread // thread système
Win32_share // partager
Win32_networkClient // Le client en ligne installé
Win32_networkprotocol // Le protocole réseau installé
Pour des informations complètes et des listes détaillées de la classe WMI Win32, veuillez vous référer à MSDN:
http://msdn2.microsoft.com/en-s/library/aa394084 (vs.85) .aspx
Exemple:
Copier le code du code comme suit:
Fonction Button1_OnClick () {// Informations CPU
var local = new activeXObject ("wbemscripting.swbemlocator");
var service = local.connectServer (".");
Var Properties = Service.execQuery ("SELECT * FROM WIN32_PROCESSOR");
var e = nouvel énumérateur (propriétés);
Document.Write ("<Table Border = 1>");
pour (;! 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.availabilité +" </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>");
}
Fonction Button2_OnClick () {// Informations CD-ROM
var local = new activeXObject ("wbemscripting.swbemlocator");
var service = local.connectServer (".");
Var Properties = Service.execQuery ("SELECT * FROM WIN32_CDROMDRIVE");
var e = nouvel énumérateur (propriétés);
Document.Write ("<Table Border = 1>");
pour (;! 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>");
}
Fonction Button3_OnClick () {// Informations sur le clavier
var local = new activeXObject ("wbemscripting.swbemlocator");
var service = local.connectServer (".");
Var Properties = Service.ExecQuery ("SELECT * FROM WIN32_KEYBOOD");
var e = nouvel énumérateur (propriétés);
Document.Write ("<Table Border = 1>");
pour (;! 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>");
}
Fonction Button4_OnClick () {// Informations sur la carte mère
var local = new activeXObject ("wbemscripting.swbemlocator");
var service = local.connectServer (".");
Var Properties = Service.ExecQuery ("SELECT * FROM WIN32_BASEBOED");
var e = nouvel énumérateur (propriétés);
Document.Write ("<Table Border = 1>");
pour (;! e.atend (); e.movEnext ())
{{
var p = e.item ();
Document.Write ("<Ter>");
document.write ("<td>" "+ p.hostingboard +" </td> ");
Document.Write ("<Td>" "+ P.Manufufacturer +" </td> ");
Document.Write ("<Td>" + P.PoweDon + "</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>");
}
De plus, vous pouvez également obtenir les informations pertinentes de la manière suivante:
Copier le code du code comme suit:
<Html> <A-Head> <Title> WMI Scripting HTML </TITLE>
<Meta http-equiv = contenu-type contenu = "text / html; charset = gb2312">
<Script Language = JScript Event = "OnCompleted (HRESULT, PerrorObject, PasyncConText)" pour = 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 ();
</cript>
<Script Language = JScript Event = OnObjectArey (objObject, ObjasyncConText) pour = foo>
if (objObject.ipeNabled! = null && objObject.ipeNabled! = "Undefined" && objObject.ipeNabled == true)
{{
If (objObject.macAddress! = Null && objObject.macAddress! = "Undefined")
Macaddr = object.macAddress;
if (objObject.ipeNabled && objObject.IpAddress (0)! = null && objObject.ipadddress (0)! = "Undefined")
Ipaddr = object.ipAddress (0);
if (objObject.dnshostName! = null && objObject.dnshostName! = "Undefined")
sdnsname = object.dnshostname;
}
</cript>
<Meta Content = "MSHTML 6.00.2800.1106" Name = Generator> </ Head>
<body>
<Objet id = local classid = clsid: 76a64158-cb41-11d1-8b02-00600806d9b6 Viewastext> </ objet>
<Objet id = foo classid = clsid: 75718c9a-f029-11d1-a1ac-004fb6c223> </bject>
<Script Language = JScript>
var service = local.connectServer ();
var macaddr;
var iPaddr;
var domainddr;
var sdnsname;
Service.Security_.ImpersonationLevel = 3;
Service.instancesofasync (foo, 'win32_networkadapterconfiguration');
</cript>
<Form id = "formfoo" name = "formarbar" action = "index.do" metheth = "post"> <input value = "00-11-11-b4-52-ef" name = "txtmacaddr"> <entrée Value = "210.42.38.50" name = "txtipaddr"> <input value = "zhupan" name = "txtdnsname"> </ body> </html>
Copier le code du code comme suit:
En fait, la chose la plus importante est d'utiliser deux ActiveX:
<Objet id = local classid = clsid: 76a64158-cb41-11d1-8b02-00600806d9b6 Viewastext> </ objet>
<Objet id = foo classid = clsid: 75718c9a-f029-11d1-a1ac-004fb6c223> </bject>
Cependant, ces deux ActiveX sont systématiquement construits, sans avoir à télécharger ou à s'inscrire.
Le travail suivant consiste à interagir avec ActiveX avec les scripts
<html>
<adal>
<script lingots = "javascript" type = "text / javascript">
fonction getcode () {
var local = new activeXObject ("wbemscripting.swbemlocator");
var service = local.connectServer (".");
Var Properties = Service.ExecQuery ("SELECT * FROM WIN32_NETWORKADAPTERCONFIGURATION WHERE IPENABLD = true");
var e = nouvel énumérateur (propriétés);
Document.Write ("<Table Border = 1>");
pour (;! 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>);
// Casser;
//}
}
Document.Write ("</ Table>");
}
</cript>
</ head>
<body>
<Button id = "test" value = "test" onclick = "getcode ()"> test </ftont>
</docy>
</html>
Classe Win32_NetWorkAdapterConfiguration: CIM_SETting
{{
Boolean ArpalwaysSourCeroute;
booléen arpuseethersnap;
Légende de chaîne;
String databasepath;
Boolean DeadgwDetecTenabled;
String defaultIpgateway [];
Uint8 defaultTos;
Uint8 defaultTl;
description de la chaîne;
Booléen dhcPeabled;
DateTime dhcPleaseExpires;
DateTime dhcPleaseObtaine;
String dhcPSserver;
chaîne dnsdomain;
String dnsDomainsuffixSearchordr [];
Booléen dnSenabledForwinsrsolution;
String dnshostName;
String dnsServerSearchOrder [];
Boolean DomainDnsRegistratinabled;
Uint32 ForwardBufferMemory;
Boolean FullDnsRegistrationNabled;
uint16 GatewayCostMetric [];
Uint8 igmplevel;
Index uint32;
UInt32 InterfaceIndex;
String iPaddress [];
Uint32 ipConnectionMetric;
Boolean IPEnabled;
Booléen ipfiltersecurityAnabled;
Boolean ipportSecurityAdAd;
String iPSecPermiPtipRotoCols [];
String iPsecpermittcpports [];
String iPSecPermiTUDPPorts [];
String iPSubNet [];
Booléen ipusezeroBroadcast;
String ipxAddress;
Booléen ipxenabled;
Uint32 ipxframetype [];
Uint32 ipxmediaType;
String ipxnetworkNumber [];
String ipxVirtualNetNumber;
Uint32 keepaliveinterval;
Uint32 keepalivetime;
String macAddress;
Uint32 mtu;
Uint32 ChicForwardPackets;
Booléen pmtubhDetecTenabled;
Booléen pmtudiscoveryed;
String Service;
String SettingId;
UInt32 TCPIPNETBIOSOPTIONS;
UInt32 TCPMaxConnectRetRansmissions;
UInt32 TCPMaxDatareTransmensions;
Uint32 tcpNumConnections;
Boolean TCPUserFC111222RENTPOINTER;
Uint16 tcpwindowSize;
Booléen winSenablelMhostsLookup;
String winShostlookupfile;
String WinsPrimaryServer;
String winsScopeId;
String winssecondaryServer;
};