📄 nettools.shtml.htm
字号:
<HTML>
<!-- Header information-->
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Author" CONTENT="Chris Maunder">
<TITLE>Misc - Net Tools</TITLE>
</HEAD>
<!-- Set background properties -->
<body background="../fancyhome/back.gif" tppabs="http://www.codeguru.com/fancyhome/back.gif" bgcolor="#FFFFFF" link="#B50029" vlink="#8E2323" alink="#FF0000">
<!-- A word from our sponsors... -->
<table WIDTH="100%">
<tr WIDTH="100%"><td><td></tr>
</table>
<!-- Article Title -->
<CENTER><H3><FONT COLOR="#AOAO99">
Net Tools
</FONT></H3></CENTER>
<CENTER><H3><HR></H3></CENTER>
<!-- Author and contact details -->
This article was contributed by <A HREF="mailto:fforest@cyberenet.net">Fred Forester</A>.
<!-- Sample image and source code/demo project -->
<P><A HREF="nettools.zip" tppabs="http://www.codeguru.com/misc/nettools.zip">Download Source Code and Example</A></p>
<br>
<!-- The article... -->
<P>The NETTOOLS project is an example of how to interface with Microsoft抯 ICMP.DLL and INETMIB.DLL.
These somewhat documented DLL抯 are supplied by Microsoft to allow MS抯 DOS
programs PING, TRACERT and NETSTAT access to the low-level IP header and MIB information.
Since MS抯 Winsock implementation does not support RAW sockets they had to create this API
For themselves. Thanks to many hackers with nothing else to do we too can use the API.
MS does say 慖t Will Go Away" so keep this in mind!</P>
<h4>PING/TRACERT </h4>
<P>The PING and TRACERT code is implemented as an MFC thread. The main app
Creates and Starts the thread when the app is started. The thread then just sits
There and waits for the app to POST a request. Once the operation is started
The thread posts a message back to the app for each line of output to be displayed
In the main apps LISTBOX. A structure is used to pass information from
The PING/TRACERT dialog box to the thread. The reason for the thread
Is the ICMP.DLL. It uses the ASYNCH calls to Winsock. If you didn抰
Process the DLL calls in a thread the user would be HourGlassed! The thread
Also allows the user to cancel the request.
<P>Info on ICMP.DLL can be found in the SDK. You can download the Platform
SDK additional component section or you can find it on the Internet at
Various sites.</P>
<P>The Pingthread.cpp and .h files contain all the code to handle PING and
TRACERT requests. Pingparmlist.h contains the structure for passing
The parameters. </P>
<P>
</FONT>
<TABLE BORDER CELLSPACING=0 CELLPADDING=0 WIDTH=590>
<TR><TD WIDTH="50%" VALIGN="TOP">
<FONT SIZE=2><P>Nettools.h</FONT></TD>
<TD WIDTH="50%" VALIGN="TOP">
<FONT SIZE=2><P>Contains the define statements for the user messages being used by the Threads.</FONT></TD>
</TR>
<TR><TD WIDTH="50%" VALIGN="TOP">
<FONT SIZE=2><P>Mainfrm.h</FONT></TD>
<TD WIDTH="50%" VALIGN="TOP">
<FONT SIZE=2><P> Contains function prototypes for the user messages and Allocates the thread class and the parmlist Structure.</P>
</FONT></TD>
</TR>
<TR><TD WIDTH="50%" VALIGN="TOP">
<FONT SIZE=2><P>Mainfrm.cpp</FONT></TD>
<TD WIDTH="50%" VALIGN="TOP">
<FONT SIZE=2><P>Contains the code to process the messages from
The thread creates the events that are used to start and stop the thread, create the thread, starts and stops the thread. </P>
</FONT></TD>
</TR>
</TABLE>
<P>The way the thread works is a little strange, plus I was just learning how to
Do threads when I wrote this. I used EVENTS to Initiate and Terminate the
Thread via the Frame. The thread itself uses windows user messages to
Post back the data from the operation. </P>
<P>The mainfrm constructor creates the events then creates a new thread.
The thread classes start function is then called. If the thread is created
The thread waits for the app to set the StartPing event. This tells the
Thread to wake up and process a request. The app then goes about its
Business until the thread posts a USER message back. </P>
<h4>Pingthread.cpp </h4>
<TABLE BORDER CELLSPACING=0 CELLPADDING=0 WIDTH=590>
<TR><TD WIDTH="48%" VALIGN="TOP">
<FONT SIZE=2><P>CpingThreadProc</FONT></TD>
<TD WIDTH="52%" VALIGN="TOP">
<FONT SIZE=2><P>a global function that IS the THREAD. Wait to be started. If started were We also asked to die, if not then process A TRACERT or PING. Post msg when done. Go back to sleep (waiting for start event).
Set the PingDead event if we were asked To die.
(in this case at app termination).</P>
</FONT></TD>
</TR>
<TR><TD WIDTH="48%" VALIGN="TOP">
<FONT SIZE=2><P>Start()</FONT></TD>
<TD WIDTH="52%" VALIGN="TOP">
<FONT SIZE=2><P>call the CreateThread and InitInstance functions. InitInstance starts Winsock this is required prior to using the ICMP.DLL plus the thread is also making Winsock calls to resolve Hostnames and addresses. Then load ICMP and store the address of the functions being Used.</P>
</FONT></TD>
</TR>
<TR><TD WIDTH="48%" VALIGN="TOP">
<FONT SIZE=2><P>Icmp_SetOpts()</FONT></TD>
<TD WIDTH="52%" VALIGN="TOP">
<FONT SIZE=2><P>Sets up the IP options for ICMP. The IP options are basically the same values used in an IP header. </P>
<P> </FONT></TD>
</TR>
<TR><TD WIDTH="48%" VALIGN="TOP">
<FONT SIZE=2><P>ProcessReply()</FONT></TD>
<TD WIDTH="52%" VALIGN="TOP">
<FONT SIZE=2><P>Does just that. It breaks up the ICMP reply plus
any network info returned. I.e. route info
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -