Previous Tip  |  Next Tip  |  Design Tips   | [Bill's Home]

128. Enhancing the Emulator

[Expand] The emulator created in the previous example was a bit basic, so let's enhance it to support a proper networking command. One of the most widely used is IPCONFIG, which allows a user to determine the networking parameters of a host. The following shows an example:

[Expand][EXE]

For this I've tidied up the program. The main change is to create a message array which displays the messge for each command (textmsg[]). I've also created a Listener on the movie to catch keystrokes.

init();
inp1.text="";
textmsg = new Array();

textmsg[0]="<P>Can't find command: " + str + "<BR>TRY <B>HELP</B> (or ?)<BR>";
textmsg[1]="<P>ipconfig /? Display this help message<br>ipconfig /all Display full configuration information.<br>ipconfig /release Release the IP address for the specified adapter.<br>ipconfig /renew Renew the IP address for the specified adapter.<br>ipconfig /flushdns Purges the DNS Resolver cache.<br>ipconfig /registerdns Refreshes all DHCP leases and re-registers DNS names<br>ipconfig /displaydns Display the contents of the DNS Resolver Cache.<br>ipconfig /showclassid Displays all the dhcp class IDs allowed for adapter.<br>ipconfig /setclassid Modifies the dhcp class id. /? Display this help message<br>ipconfig /all Display full configuration information.<br>ipconfig /release Release the IP address for the specified adapter.<br>ipconfig /renew Renew the IP address for the specified adapter.<br>ipconfig /flushdns Purges the DNS Resolver cache.<br>ipconfig /registerdns Refreshes all DHCP leases and re-registers DNS names<br>ipconfig /displaydns Display the contents of the DNS Resolver Cache.<br>ipconfig /showclassid Displays all the dhcp class IDs allowed for adapter.<br>ipconfig /setclassid Modifies the dhcp class id. /renew Renew the IP address for the specified adapter.<br>/flushdns Purges the DNS Resolver cache.<br>/registerdns Refreshes all DHCP leases and re-registers DNS names<br>/displaydns Display the contents of the DNS Resolver Cache.<br>/showclassid Displays all the dhcp class IDs allowed for adapter.<br>/setclassid Modifies the dhcp class id. <P>";
textmsg[2]="<p>Ethernet adapter Wireless Network Connection:</p><p> Connection-specific DNS Suffix . :<br> IP Address. . . . . . . . . . . . : 192.168.0.19<br> Subnet Mask . . . . . . . . . . . : 255.255.255.0<br> Default Gateway . . . . . . . . . :</p><p>Ethernet adapter Local Area Connection:</p><p> Connection-specific DNS Suffix . : napier.ac.uk<br> IP Address. . . . . . . . . . . . : 146.176.162.24<br> Subnet Mask . . . . . . . . . . . : 255.255.255.0<br> Default Gateway . . . . . . . . . : 146.176.162.254</p>";
textmsg[3]="USAGE:<br>ipconfig [/? | /all | /renew [adapter] | /release [adapter] |<br>/flushdns | /displaydns | /registerdns |<br>/showclassid adapter |<br>/setclassid adapter [classid] ]<p>where<br> adapter Connection name<br> (wildcard characters * and ? allowed, see examples)</p><p> Options:<br> /? Display this help message<br> /all Display full configuration information.<br> /release Release the IP address for the specified adapter.<br> /renew Renew the IP address for the specified adapter.<br> /flushdns Purges the DNS Resolver cache.<br> /registerdns Refreshes all DHCP leases and re-registers DNSnames<br> /displaydns Display the contents of the DNS Resolver Cache.<br> /showclassid Displays all the dhcp class IDs allowed for adapter.<br> /setclassid Modifies the dhcp class id.</p><p>The default is to display only the IP address, subnet mask and<br> default gateway for each adapter bound to TCP/IP.</p><p>For Release and Renew, if no adapter name is specified, then the IP address<br> leases for all adapters bound to TCP/IP will be released or renewed.</p><p>For Setclassid, if no ClassId is specified, then the ClassId is removed.</p><p>Examples:<br> &gt; ipconfig ... Show information.<br> &gt; ipconfig/all ... Show detailed information<br> &gt; ipconfig /renew ... renew all adapters<br> &gt; ipconfig /renew EL* ... renew any connection that has its<br> name starting with EL<br> &gt; ipconfig /release *Con* ... release all matching connections,<br> eg. &quot;Local Area Connection 1&quot; or<br> &quot;Local Area Connection 2&quot;</p>";
textmsg[4]="<p><br> Windows IP Configuration</p><p> Host Name . . . . . . . . . . . . : ME1D031-006662<br> Primary Dns Suffix . . . . . . . : napier-mail.napier.ac.uk<br> Node Type . . . . . . . . . . . . : Peer-Peer<br> IP Routing Enabled. . . . . . . . : No<br> WINS Proxy Enabled. . . . . . . . : No<br> DNS Suffix Search List. . . . . . : napier-mail.napier.ac.uk<br> napier.ac.uk<br> ac.uk</p><p>Ethernet adapter Wireless Network Connection:</p><p> Connection-specific DNS Suffix . :<br> Description . . . . . . . . . . . : Cisco Systems 350 Series PCI Wirele<br> s LAN Adapter<br> Physical Address. . . . . . . . . : 00-09-7C-85-87-F1<br> Dhcp Enabled. . . . . . . . . . . : No<br> IP Address. . . . . . . . . . . . : 192.168.0.19<br> Subnet Mask . . . . . . . . . . . : 255.255.255.0<br> Default Gateway . . . . . . . . . :</p><p>Ethernet adapter Local Area Connection:</p><p> Connection-specific DNS Suffix . : napier.ac.uk<br> Description . . . . . . . . . . . : 3Com EtherLink XL 10/100 PCI For Co<br> plete PC Management NIC (3C905C-TX)<br> Physical Address. . . . . . . . . : 00-04-76-25-FB-BF<br> Dhcp Enabled. . . . . . . . . . . : Yes<br> Autoconfiguration Enabled . . . . : Yes<br> IP Address. . . . . . . . . . . . : 146.176.162.24<br> Subnet Mask . . . . . . . . . . . : 255.255.255.0<br> Default Gateway . . . . . . . . . : 146.176.162.254<br> DHCP Server . . . . . . . . . . . : 146.176.2.205<br> DNS Servers . . . . . . . . . . . : 146.176.1.5<br> 146.176.2.5<br> Primary WINS Server . . . . . . . : 146.176.2.204<br> Secondary WINS Server . . . . . . : 146.176.2.205<br> Lease Obtained. . . . . . . . . . : 08 May 2003 08:49:13<br> Lease Expires . . . . . . . . . . : 11 May 2003 08:49:13</p>";
textmsg[5]="<p>Renew the IP address for the specified adapter. NOT IMPLEMENTED YET!</p>";
textmsg[6]="<p>Release the IP address for the specified adapter. NOT IMPLEMENTED YET!</p>";
textmsg[7]="<p>Purges the DNS Resolver cache. NOT IMPLEMENT YET!</P>";
textmsg[8]="<p>Display the contents of the DNS Resolver Cache. NOT IMPLEMENT YET!</P>";
textmsg[9]="<p>Modifies the dhcp class id. NOT IMPLEMENT YET!</P>";


myListener = new Object();
myListener.onKeyDown = function () {
trace("Press" + Key.getAscii());
if (Key.getAscii()==13)
{
test1();
inp1.text="";

}
else inp1.text=inp1.text+chr(Key.getAscii());

}
myListener.onKeyUp = function () {
trace ("You released a key." + Key.getCode());
}


function test1() {
str=inp1.text;
str=str.toLowerCase();
if (str=="help" || str=="?") disp.htmltext= "<B>&gt; HELP</B><BR>" + textmsg[1];
else if (str=="ipconfig") disp.htmltext= "<B>&gt; IPCONFIG</B><BR>" + textmsg[2];
else if (str=="ipconfig /?") disp.htmltext="<B>&gt; IPCONFIG /?</B><BR>" + textmsg[3];
else if (str=="ipconfig /all") disp.htmltext="<B>&gt; IPCONFIG /all</B><BR>" + textmsg[4];
else if (str=="ipconfig /renew") disp.htmltext="<B>&gt; IPCONFIG /renew</B><BR>" + textmsg[5];
else if (str=="ipconfig /release") disp.htmltext="<B>&gt; IPCONFIG /release</B><BR>" + textmsg[6];
else if (str=="ipconfig /flushdns") disp.htmltext="<B>&gt; IPCONFIG /flushdns</B><BR>" + textmsg[7];
else if (str=="ipconfig /displaydns") disp.htmltext="<B>&gt; IPCONFIG /displaydns</B><BR>" + textmsg[7];
else if (str=="ipconfig /showclassid") disp.htmltext="<B>&gt; IPCONFIG /showclassid</B><BR>" + textmsg[7];
else if (str=="ipconfig /setclassid") disp.htmltext="<B>&gt; IPCONFIG /setclassid</B><BR>" + textmsg[7];
else { disp.htmltext= "<B>&gt; " + str +"</B><BR>" + textmsg[0]; }
disp.scroll++;

}

Key.addListener(myListener);