In order to obtain the MAC address of each computer in a dry dormitory, we want to provide the MAC address of the client in the form of a webpage because many computers are not familiar with the operation and cannot directly introduce commands, click Submit to submit the database to the server.
The most common solution on the network is to use JavaScript scripts and actually use two objects, but its disadvantage is: in the IE Security Attribute of the client, you must set "initialize ActiveX controls that are not marked as secure and run scripts" to "enable ". This operation is not only complex, but also reduces the security of the client.CodeDisadvantages: keyword such as event and for is not the XHTML standard.
The main code of this solution is as follows:
<Script language = "jscript" event = "oncompleted (hresult, perrorobject, pasynccontext )"
For = "foo" type = "text/JavaScript">
Document. Forms [0]. txtrr. value = Unescape (Sall );
</SCRIPT>
<Object ID = "locator" classid = "CLSID: 76a64158-cb41-11d1-8b02-00600806d9b6">
</Object>
<Object ID = "foo" classid = "CLSID: 75718c9a-f029-11d1-a1ac-00c04fb6c223">
</Object>
<Script language = "jscript" type = "text/JavaScript">
VaR service = locator. connectserver ();
VaR Sall = "";
Service. Security _. impersonationlevel = 3;
Service. instancesofasync (Foo, 'win32 _ networkadapterconfiguration ');
</SCRIPT>
Another method is to execute the doscommand NBTSTAT on the server side, but its limitations are too large. Basically, it can only be successful within the LAN, and the firewall will become invalid once it encounters. This task does not work, so I did not test it.
Solution 2: the client executes the doscommand ipconfig to upload the generated information to the server.
Run the following code to execute the doscommand:
Wshshell = new activexobject ("wscript. Shell ")
Wshshell. Run ("cmd.exe/C ipconfig/All> C: \ 1.txt ")
However, if you want to upload c: \ 1.txt, you may encounter a problem. The webpage's input file control must be user-selected before uploading. But I can't fix a file.
Code is not required for uploading files: the client is as follows:
<Form ID = "form1" method = "Post" enctype = "multipart/form-Data" runat = "server">
<Input id = "file1" type = "file" runat = "server"/> <br/>
<Input type = "Submit" id = "butup" value = "Upload"/>
</Form>
The server is as follows:
If (this. ispostback)
{
If (file1.postedfile. contentlength! = 0)
{
File1.postedfile. saveas ("C: \ Inetpub \ wwwroot \ get \ FJ \ a.txt ");
}
}
Later, I want to read c: \ 1.txt into the text box and upload it again.
VaR forreading = 1;
FSO = new activexobject ("scripting. FileSystemObject ");
TS = FSO. opentextfile ("C :\\ 1.txt", forreading );
Document. getelementbyid ("txt1"). value = ts. readall (). Replace (/\ r \ n/g ,"");
There is another activexobject here. If the preceding wscript can be used, it will certainly be used here.