[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.vb.general.discussion

Good site/book for TCP/IP basics?

Tony Toews

11/28/2010 10:25:00 PM

Folks

What is a good site for sample code and such for TCP/IP basics?

I have a Windows 2003 web/DNS/email server which every month or two
stops responding to network requests. I've recently determined that
if you disable/re-enable the network connection it happily keeps on
going. (In the past we've just rebooted the system or abruptly
powered it off.)

So I'm thinking a small VB6 program which pings (or equivalent) the
router/DSL modem IP Address every minute. If no response then
disable/reenable the network connection.

And, of course, log/email the problem so I can monitor this. But that
part I know how to do.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...
9 Answers

Ron Weiner

11/29/2010 1:12:00 AM

0

Tony Toews formulated on Sunday :
> Folks
>
> What is a good site for sample code and such for TCP/IP basics?
>
> I have a Windows 2003 web/DNS/email server which every month or two
> stops responding to network requests. I've recently determined that
> if you disable/re-enable the network connection it happily keeps on
> going. (In the past we've just rebooted the system or abruptly
> powered it off.)
>
> So I'm thinking a small VB6 program which pings (or equivalent) the
> router/DSL modem IP Address every minute. If no response then
> disable/reenable the network connection.
>
> And, of course, log/email the problem so I can monitor this. But that
> part I know how to do.
>
> Tony

Once upon a time there was a most excelent site at
http://www..... Sadly this site seems to have dissapeared.
Anyway they posted the sample code I have pasted bwlow that i have used
in projects before. Help yourself.

Ron Weiner

Const SOCKET_ERROR = 0
Private Type WSAdata
wVersion As Integer
wHighVersion As Integer
szDescription(0 To 255) As Byte
szSystemStatus(0 To 128) As Byte
iMaxSockets As Integer
iMaxUdpDg As Integer
lpVendorInfo As Long
End Type
Private Type Hostent
h_name As Long
h_aliases As Long
h_addrtype As Integer
h_length As Integer
h_addr_list As Long
End Type
Private Type IP_OPTION_INFORMATION
TTL As Byte
Tos As Byte
Flags As Byte
OptionsSize As Long
OptionsData As String * 128
End Type
Private Type IP_ECHO_REPLY
Address(0 To 3) As Byte
Status As Long
RoundTripTime As Long
DataSize As Integer
Reserved As Integer
data As Long
Options As IP_OPTION_INFORMATION
End Type
Private Declare Function GetHostByName Lib "wsock32.dll" Alias
"gethostbyname" (ByVal HostName As String) As Long
Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal
wVersionRequired&, lpWSAdata As WSAdata) As Long
Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory"
(hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Private Declare Function IcmpCreateFile Lib "icmp.dll" () As Long
Private Declare Function IcmpCloseHandle Lib "icmp.dll" (ByVal HANDLE
As Long) As Boolean
Private Declare Function IcmpSendEcho Lib "ICMP" (ByVal IcmpHandle As
Long, ByVal DestAddress As Long, ByVal RequestData As String, ByVal
RequestSize As Integer, RequestOptns As IP_OPTION_INFORMATION,
ReplyBuffer As IP_ECHO_REPLY, ByVal ReplySize As Long, ByVal TimeOut As
Long) As Boolean
Private Sub Form_Load()
'KPD-Team 2000
'URL: http://www..../
'E-Mail: KPDTeam@Allapi.net
Const HostName = "www.allapi.net"
Dim hFile As Long, lpWSAdata As WSAdata
Dim hHostent As Hostent, AddrList As Long
Dim Address As Long, rIP As String
Dim OptInfo As IP_OPTION_INFORMATION
Dim EchoReply As IP_ECHO_REPLY
Call WSAStartup(&H101, lpWSAdata)
If GetHostByName(HostName + String(64 - Len(HostName), 0)) <>
SOCKET_ERROR Then
CopyMemory hHostent.h_name, ByVal GetHostByName(HostName +
String(64 - Len(HostName), 0)), Len(hHostent)
CopyMemory AddrList, ByVal hHostent.h_addr_list, 4
CopyMemory Address, ByVal AddrList, 4
End If
hFile = IcmpCreateFile()
If hFile = 0 Then
MsgBox "Unable to Create File Handle"
Exit Sub
End If
OptInfo.TTL = 255
If IcmpSendEcho(hFile, Address, String(32, "A"), 32, OptInfo,
EchoReply, Len(EchoReply) + 8, 2000) Then
rIP = CStr(EchoReply.Address(0)) + "." +
CStr(EchoReply.Address(1)) + "." + CStr(EchoReply.Address(2)) + "." +
CStr(EchoReply.Address(3))
Else
MsgBox "Timeout"
End If
If EchoReply.Status = 0 Then
MsgBox "Reply from " + HostName + " (" + rIP + ") recieved
after " + Trim$(CStr(EchoReply.RoundTripTime)) + "ms"
Else
MsgBox "Failure ..."
End If
Call IcmpCloseHandle(hFile)
Call WSACleanup
End Sub


Tony Toews

11/29/2010 3:23:00 AM

0

On Sun, 28 Nov 2010 20:11:59 -0500, Ron Weiner <NoOne@NoWare.NutThing>
wrote:

>Once upon a time there was a most excelent site at
>http://www.....

Ah, yes, that was the site I recall bookmarking a while back and
unable to locate.

Thanks for the code. I'll muck with that.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...

Jason Keats

11/29/2010 8:49:00 AM

0

Ron Weiner wrote:

> Once upon a time there was a most excelent site at
> http://www..... Sadly this site seems to have dissapeared. Anyway
> they posted the sample code I have pasted bwlow that i have used in
> projects before. Help yourself.
>

That site is now at: http://allapi.men...

(nobody)

11/29/2010 3:17:00 PM

0

"Tony Toews" <ttoews@telusplanet.net> wrote in message
news:mbl5f6t9qsihb0934j6jub3i0bgbiriget@4ax.com...
> Folks
>
> What is a good site for sample code and such for TCP/IP basics?
>
> I have a Windows 2003 web/DNS/email server which every month or two
> stops responding to network requests. I've recently determined that
> if you disable/re-enable the network connection it happily keeps on
> going. (In the past we've just rebooted the system or abruptly
> powered it off.)
>
> So I'm thinking a small VB6 program which pings (or equivalent) the
> router/DSL modem IP Address every minute. If no response then
> disable/reenable the network connection.
>
> And, of course, log/email the problem so I can monitor this. But that
> part I know how to do.

I would first check Event Viewer, perhaps there is a service auto stopping.
This is usually mentioned in the System log. You can export the list of
services and their status to a text file, then compare it after the problem
happens using WinMerge.

If there is a service stopping, you can go to the service properties, and in
Recovery tab, let Windows auto restart it when it stops. If you want to ping
from VB, some have provided a sample, but here is another one:

http://vbnet.mvps.org/code/interne...

To see the list of services, and whether they are stopped, see this code:

http://vbnet.mvps.org/code/network/enumservicesadv...

You need to call OpenService/StartService/CloseServiceHandle, if you want to
start a specific service. As for enabling/reenabling the adapter, I am not
sure if calling IP Helper API functions such as IpRenewAddress() is enough,
or shelling to "ipconfig" or similar. There are other groups of functions
that start with "SetupDi" and "CM_" that deal with Device Manager, but you
need to do a lot of calls just to do something small.


Karl E. Peterson

11/30/2010 12:28:00 AM

0

Tony Toews submitted this idea :
> On Sun, 28 Nov 2010 20:11:59 -0500, Ron Weiner <NoOne@NoWare.NutThing>
> wrote:
>
>> Once upon a time there was a most excelent site at
>> http://www.....
>
> Ah, yes, that was the site I recall bookmarking a while back and
> unable to locate.

http://web.archiv...20060613010616/http://www..../

and/or

http://web.archiv...*/http://www....

--
..NET: It's About Trust!
http://vfre...


Karl E. Peterson

11/30/2010 12:29:00 AM

0

Jason Keats wrote on 11/29/2010 :
> Ron Weiner wrote:
>
>> Once upon a time there was a most excelent site at
>> http://www..... Sadly this site seems to have dissapeared. Anyway
>> they posted the sample code I have pasted bwlow that i have used in
>> projects before. Help yourself.
>
> That site is now at: http://allapi.men...

Much better alternative to archive.org!

--
..NET: It's About Trust!
http://vfre...


Ron Weiner

11/30/2010 1:32:00 AM

0

Jason Keats presented the following explanation :
> Ron Weiner wrote:
>
>> Once upon a time there was a most excelent site at
>> http://www..... Sadly this site seems to have dissapeared. Anyway
>> they posted the sample code I have pasted bwlow that i have used in
>> projects before. Help yourself.
>>
>
> That site is now at: http://allapi.men...

Thank You! Good to be able to have access to this site again.

Ron Weiner


Tony Toews

12/3/2010 12:59:00 AM

0

On Mon, 29 Nov 2010 10:16:38 -0500, "Nobody" <nobody@nobody.com>
wrote:

>I would first check Event Viewer, perhaps there is a service auto stopping.
>This is usually mentioned in the System log. You can export the list of
>services and their status to a text file, then compare it after the problem
>happens using WinMerge.

Nothing in the event log. Just the standard stuff.

It just occurred to me that restarting Windows would also work.
After all that's what we've done in the past. (I also have an iBoot
connected but that's rather harsh to abruptly power down a system.)

And I'm sure there's an API call or WMI call for that.

Now obviously I'd want to put in some kind of counter so if it starts
twice in under an hour to not restart the third time.

Hmm, I should also have it set to send me an email to my cell phone.
Once it's restarted of course because I can't access the network until
then. Although, given that the email server is on the same system I
can at least queue the email to be sent.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/ac...
Tony's Microsoft Access Blog - http://msmvps.com/blo...
For a convenient utility to keep your users FEs and other files
updated see http://www.autofeup...

Karl E. Peterson

12/3/2010 1:47:00 AM

0

Tony Toews expressed precisely :
> On Mon, 29 Nov 2010 10:16:38 -0500, "Nobody" <nobody@nobody.com>
> wrote:
>
>> I would first check Event Viewer, perhaps there is a service auto stopping.
>> This is usually mentioned in the System log. You can export the list of
>> services and their status to a text file, then compare it after the problem
>> happens using WinMerge.
>
> Nothing in the event log. Just the standard stuff.
>
> It just occurred to me that restarting Windows would also work.
> After all that's what we've done in the past. (I also have an iBoot
> connected but that's rather harsh to abruptly power down a system.)
>
> And I'm sure there's an API call or WMI call for that.
>
> Now obviously I'd want to put in some kind of counter so if it starts
> twice in under an hour to not restart the third time.
>
> Hmm, I should also have it set to send me an email to my cell phone.
> Once it's restarted of course because I can't access the network until
> then. Although, given that the email server is on the same system I
> can at least queue the email to be sent.

I take it the current problem, of the half-dozen or so you posted
initially <g>, is bouncing the network connection? It wouldn't
surprise me if there wasn't a way to do this through the RAS API.
(msdn.microsoft.com is down at the moment, so searching is kinda
sucky.) Don't know specifically, but maybe that's a clue?

--
..NET: It's About Trust!
http://vfre...