Pinging IPs
Pinging IPs
Pinging IPs
Pinging IPs
Pinging IPs
Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs
Pinging IPs Pinging IPs
Pinging IPs
Go Back  Xtreme Visual Basic Talk > > > Pinging IPs


Reply
 
Thread Tools Display Modes
  #1  
Old 05-20-2005, 02:36 PM
Twan Twan is offline
Contributor
 
Join Date: Apr 2003
Posts: 627
Default Pinging IPs


What do I need to do to be able to ping a bunch of IPs?
Reply With Quote
  #2  
Old 05-20-2005, 02:42 PM
HardCode's Avatar
HardCodePinging IPs HardCode is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2004
Location: New Jersey
Posts: 3,339
Default

Why do you need to ping a bunch of IPs?
__________________
DON'T CLICK HERE

Useful forum tags: [VB][/VB], [CODE][/CODE], [HTML][/HTML]
Reply With Quote
  #3  
Old 05-21-2005, 02:16 PM
Twan Twan is offline
Contributor
 
Join Date: Apr 2003
Posts: 627
Default

I need to know the lowest ping so I can use that IP in my program
Reply With Quote
  #4  
Old 05-21-2005, 05:19 PM
SystemOfADown's Avatar
SystemOfADown SystemOfADown is offline
Contributor
 
Join Date: Aug 2003
Location: My Room
Posts: 607
Default

well, im assuming you are running some sort of program on every computer you are trying to ping. so all you do is connect and send some data, and then have the other computer respond with a certain string. all you gotta do is record the time it takes between when you sent out the ping request, and when the other computer responded to it
__________________
Programmers need love too.
Reply With Quote
  #5  
Old 05-21-2005, 10:51 PM
Twan Twan is offline
Contributor
 
Join Date: Apr 2003
Posts: 627
Default Ping Program Won't Work

I made this here ping program. It won't work. It never ends up showing the fastest IP, it may be some simple mistake. I used the AllAPI example for Ping. What's wrong with this code?

Code:
Option Explicit Dim Ips() As String 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 Command1_Click() Dim i As Long Dim length As Integer Dim HostName 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 Dim FastestProxy FastestProxy = 100 Ips = Split(Text1, vbCrLf) For i = 0 To UBound(Ips) length = InStr(1, Ips(i), " ") Ips(i) = Mid(Ips(i), length, Len(Ips(i))) length = InStr(1, Ips(i), ":") Ips(i) = Mid(Ips(i), 2, Len(Ips(i)) - (Len(Ips(i)) - length + 2)) Call WSAStartup(&H101, lpWSAdata) HostName = Ips(i) 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 End If If EchoReply.Status = 0 Then MsgBox Trim$(CStr(EchoReply.RoundTripTime)) If Trim$(CStr(EchoReply.RoundTripTime)) < FastestProxy Then _ FastestProxy = Trim$(CStr(EchoReply.RoundTripTime)) + HostName Else End If DoEvents Next Call IcmpCloseHandle(hFile) Call WSACleanup MsgBox FastestProxy End Sub

Last edited by loquin; 04-09-2007 at 09:51 AM. Reason: add line breaks to code
Reply With Quote
  #6  
Old 05-22-2005, 07:25 AM
SystemOfADown's Avatar
SystemOfADown SystemOfADown is offline
Contributor
 
Join Date: Aug 2003
Location: My Room
Posts: 607
Default

Ok, maybe it's just me, but I can't see anywhere where you set the value of RoundTripTime, assuming that this is all your code.
__________________
Programmers need love too.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Pinging IPs
Pinging IPs
Pinging IPs Pinging IPs
Pinging IPs
Pinging IPs
Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs Pinging IPs
Pinging IPs
Pinging IPs
 
Pinging IPs
Pinging IPs
 
-->