Testing a valid IP address? ( SOLVED! )

User avatar
JC
Posts: 445
Joined: Thu Feb 21, 2008 11:58 am
Location: Brazil
Contact:

Post by JC »

Uwe,

One question about the tool getip: It can get the information of another machine, running into my machine?
Peace and lighting!

Júlio César M. Ferreira

FWH 8.10 / xHB 1.1.0 / xDevStudio 0.72 / Pelles C 5.0.1 / SQLLIB 1.9
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Post by anserkk »

Dear JC,

When I try
C:\>ping PC1
PC1 responds back with the IP address.

From the command prompt everything is fine.

My network contains a DOMAIN


Dear Uwe,

Thankyou for the suggestion. I have not tried the utility which you have specified. I prefer to get the results without installing any extra utility. If my app runs in a single PC then I can think of installing the utility, but what if the app is supposed to work on atleast 10 to 15 PC's in the network. Every machine needs the extra utility to be installed to get the result which I don't prefer


Regards

Anser
User avatar
JC
Posts: 445
Joined: Thu Feb 21, 2008 11:58 am
Location: Brazil
Contact:

Post by JC »

Anser,

I assume a ping into another machine on your network, by the name it, responds as it should?

Sorry for my insistence, but we need to test all of situations to resolve this problem...
Peace and lighting!

Júlio César M. Ferreira

FWH 8.10 / xHB 1.1.0 / xDevStudio 0.72 / Pelles C 5.0.1 / SQLLIB 1.9
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Post by anserkk »

Dear JC,
I assume a ping into another machine on your network, by the name it, responds as it should?
Yes Ping is reponding back by name as well as IP

Regards

Anser
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Ping ( VB-source )

Post by ukoenig »

Hello,

I found a V-Basic-source in german-forum for PING inside a application ( I don't know, if it is usefull, otherwise i can delete it again ).
Maybe it is possible to translate it to FWH ?
i translated the german-source to english

< Sensapi.dll > is used for API-function

Code: Select all


// API
Private Declare Function IsDestinationReachable Lib "Sensapi.dll" _ 
Alias "IsDestinationReachableA" (ByVal lpszDestination As String, _ 
                                     lpQOCInfo As QOCINFO) As Long 

Private Type QOCINFO 
    dwSize As Long 
    dwFlags As Long 
    dwInSpeed As Long 
    dwOutSpeed As Long 
End Type 

// PING to Server ( Returns reaction-time ) 
Public Function Ping(ByVal sHost As String) As Single 
    Dim QI As QOCINFO 
    Dim vTime As Single 
  
    QI.dwSize = Len(QI) 
    vTime = Timer 
    If IsDestinationReachable(sHost, QI) = 1 Then 
        Ping = Timer - vTime 
      Else 
        Ping = -1 
    End If 
End Function 

'How to use : 
'use in local LAN for sHost computer-name : 
Sub a() 
    Dim nTime As Single 
    
    nTime = Ping("\\computername") 
    If nTime <> -1 Then 
        MsgBox "computer not reachable : Pingtime : " & CStr(nTime) & " Seconds" 
      Else 
        MsgBox "computer not reachable !" 
    End If 
End Sub 

'Testing reaction-time of a Webserver use IP-Adress of Server or the Hostname : 
Sub b() 
    Dim nTime As Single 

    nTime = Ping("www.myAdress.de") 
    If nTime <> -1 Then 
        MsgBox "Server not reachable : Pingtime : " & CStr(nTime) & " Seconds" 
      Else 
        MsgBox "Server not reachable !" 
    End If 
End Sub 

// Or ... 
Sub c() 
    Dim nTime As Single 
    
    nTime = Ping("217.160.105.148") 
    If nTime <> -1 Then 
        MsgBox "Server not reachable : Pingtime : " & CStr(nTime) & " Seconds" 
      Else 
        MsgBox "Server not reachable !" 
    End If 
End Sub

Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
JC
Posts: 445
Joined: Thu Feb 21, 2008 11:58 am
Location: Brazil
Contact:

Post by JC »

Uwe,

This function is wonderful! I think yes, it's possible translate to FWH language! Let's go to work! :)
Peace and lighting!

Júlio César M. Ferreira

FWH 8.10 / xHB 1.1.0 / xDevStudio 0.72 / Pelles C 5.0.1 / SQLLIB 1.9
User avatar
ukoenig
Posts: 3981
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany
Contact:

Ping for Fwh

Post by ukoenig »

Hello JC,
another version I found ( a bit different and shorter returns just .T. or .F. ) :

Code: Select all


// API
Private Declare Function IsDestinationReachable Lib _
  "Sensapi.dll" Alias "IsDestinationReachableA" _
  (ByVal lpszDestination As String, _
  lpQOCInfo As QOCINFO) As Long

Private Type QOCINFO
  dwSize As Long
  dwFlags As Long
  dwInSpeed As Long
  dwOutSpeed As Long
End Type
// Ping returns .T. or .F.

Public Function Ping(ByVal IP As String) As Boolean
  Dim QuestStruct As QOCINFO
  Dim lReturn As Long

// Structure-Size
  QuestStruct.dwSize = Len(QuestStruct)

// Destination-test
  lReturn = IsDestinationReachable(IP, QuestStruct)
  
// using answer
  If lReturn = 1 Then
    // Answer .T.
    Ping = True
  Else
    // Answer .F.
    Ping = False
  End If
End Function

Infos :
DLL name: sensapi.dll or sensapi
How to find the DLL:
Typically located in: Windows instalation folder/some subfolder
Full version: 5.1.2600.1106 (xpsp1.020828-1920)
File size: 6144 bytes

Information saved in the DLL itself:
Howto display it: Press Ctrl+Enter on DLL name, then click on 'Version' tab and compare with values listed below. Please keep in mind that malicious software often saves here fake identification or author name (see disclaimer below). Some malware can use the same file name.
Author: Microsoft Corporation
Description: SENS Connectivity API DLL
Internal name: SensApi.dll
Information about Copyright: � Microsoft Corporation. All rights reserved.
Original file name: SensApi.dll
Product version: 5.1.2600.1106

Description:
Relates to: system rpm windows event api 2014 0200 internet image resource
Security risk: unknown
Description: This is a core DLL needed for Windows operating system. You should not delete it
Part of OS: YES
Designed for OS: Win NT 32

Some more infos :

EM Library: SensApi.dll error message
When running EM Library on Windows NT the error number 0x8007007e may be encountered in conjunction with a message about being unable to load system file "SensApi.dll":

0x8007007e Could not load system file "SensApi.dll"

This error message about SensApi.dll can occur on Windows NT computers where an earlier version of Internet Explorer than Internet Explorer 5 is in use.

This message should not be displayed on Windows 2000, Windows XP and Windows 2003 computers where SensApi.dll is installed as part of the operating system.

What to do
Upgrade to Internet Explorer 5, or higher.

Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Friends,

It´s really solved?

Try the code below:

Code: Select all

#include "FiveWin.ch" 
#include "dll.ch" 

Function Main(_ping_) 
   Ping( _ping_ )
   return nil

//-------------------------------------
Function Ping(DestinationAddress)
//-------------------------------------
   local IcmpHandle,Replicas
   local RequestData:="Testando ping",;
         RequestSize:=15,;
         RequestOptions:="",;
         ReplyBuffer:=space(278),;
         ReplySize:=278,;
         Timeout:=500 && Milisegundos de espera
   default DestinationAddress := "10.10.10.3"
   DestinationAddress:=left(alltrim(DestinationAddress)+space(15),15)
   IcmpHandle:=IcmpCreateFile()
   Replicas:=IcmpSendEcho(IcmpHandle,;
                          inet_addr(DestinationAddress),;
                          RequestData,;
                          RequestSize,0,;
                          ReplyBuffer,;
                          ReplySize,;
                          Timeout)
   IcmpCloseHandle(IcmpHandle)

   // Resultados
   ? "function inet_addr", inet_addr(DestinationAddress)
   ? "function NetName", NETNAME()

   WsaStartUp() // Very Important

   ? "function getHostByName with NetName", getHostByName( NETNAME() )
   ? "function getHostByAddress with IP", getHostByAddress( DestinationAddress )
   ? "function getHostByName with Google site", getHostByName( "www.google.com" )

   WsaCleanUp() // Very Important

   if Replicas > 0
      msginfo("Machine "+alltrim(DestinationAddress)+" exist")
   else
      msginfo("Machine "+alltrim(DestinationAddress)+" not existe")
   endif
   return nil

//---------------------------------------------------- 
//DLL32 FUNCTION SndPlaySound( cFile AS LPSTR, nType AS WORD ) AS BOOL PASCAL LIB "MMSYSTEM.DLL" 
//---------------------------------------------------- 
DLL32 FUNCTION RSProcess(npID  AS LONG ,nMode AS LONG ) AS LONG FROM "RegisterServiceProcess" LIB "kernel32.DLL" 
DLL32 FUNCTION GCP() AS LONG FROM "GetCurrentProcessId" LIB "kernel32.dll" 
DLL32 STATIC FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS BOOL PASCAL FROM "_FreeImage_Save@16" LIB hLib
//---------------------------------------------------- 
DLL32 FUNCTION WSAGetLastError() AS _INT PASCAL FROM "WSAGetLastError" LIB "wsock32.dll"
DLL32 FUNCTION inet_addr(cIP AS STRING) AS LONG PASCAL FROM "inet_addr" LIB "wsock32.dll"
DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "icmp.dll"
DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "icmp.dll"
DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
                            DestinationAddress AS LONG,;
                            RequestData AS STRING,;
                            RequestSize AS LONG,;
                            RequestOptions AS LONG,;
                            ReplyBuffer AS LPSTR,;
                            ReplySize AS LONG,;
                            Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "icmp.dll"
User avatar
anserkk
Posts: 1280
Joined: Fri Jun 13, 2008 11:04 am
Location: Kochi, India

Post by anserkk »

Thank you Mr.Rochinha,

I tested and It is working

Regards

Anser
User avatar
JC
Posts: 445
Joined: Thu Feb 21, 2008 11:58 am
Location: Brazil
Contact:

Post by JC »

Rochinha,

Wonderful! Perfect function!
Maravilhoso! Função perfeita meu garoto!

Resolveu muitos dos problemas com teste de conexão aqui no nosso sistema! Valeu!
Peace and lighting!

Júlio César M. Ferreira

FWH 8.10 / xHB 1.1.0 / xDevStudio 0.72 / Pelles C 5.0.1 / SQLLIB 1.9
User avatar
Patrick Mast
Posts: 244
Joined: Sat Mar 03, 2007 8:42 pm

Post by Patrick Mast »

Hey Guys,

Sorry but I can not get this to work on my Wndows Vista computer. It compiles ok, but the exe just does not do anything. Do you have a running sample?

Patrick
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Patrick,

Download at http://www.5volution.com/forum/pinga.zip

This version is tested on Vista Ultimate and Windows server 2003.

Use: pinga <ip> example: pinga 192.168.0.100
Rochinha
Posts: 309
Joined: Sun Jan 08, 2006 10:09 pm
Location: Brasil - Sao Paulo
Contact:

Post by Rochinha »

Friends,

Here is a new version:

Code: Select all

#include "FiveWin.ch" 
#include "dll.ch" 

Function Main(_ping_) 
   Ping( _ping_ )
   return nil

Function Ping(DestinationAddress)
   local IcmpHandle,Replicas
   local RequestData:="Testando ping",;
         RequestSize:=15,;
         RequestOptions:="",;
         ReplyBuffer:=space(278),;
         ReplySize:=278,;
         Timeout:=500 && Milisegundos de espera
   default DestinationAddress := "0.0.0.0"
   DestinationAddress:=left(alltrim(DestinationAddress)+space(15),15)
   IcmpHandle:=IcmpCreateFile()
   Replicas:=IcmpSendEcho(IcmpHandle,;
                          inet_addr(DestinationAddress),;
                          RequestData,;
                          RequestSize,0,;
                          ReplyBuffer,;
                          ReplySize,;
                          Timeout)
   IcmpCloseHandle(IcmpHandle)

   CursorWait()

   // Resultados
   nInetAddr             := inet_addr(DestinationAddress)
   cNetName              := NETNAME()
   cgetHostName          := getHostName() //, Valtype( getHostName() )
   cgetNetCardID         := getNetCardID()

   cIPExtern := getIPExtern( "http://www.5volution.com/meuip.asp" )

   WsaStartUp() // Very Important

   cgetHostByName_NetName:= getHostByName( NETNAME() )
   cgetHostByAddress_IP  := getHostByAddress( DestinationAddress )
   cgetHostByName_Google := getHostByName( "www.google.com" )

   WsaCleanUp() // Very Important

   ? "function inet_addr: " + str(inet_addr(DestinationAddress)),;
     "function NetName: " + cNetName,;
     "function getHostName: " + cgetHostName,;
     "function getNetCardID: " + cgetNetCardID,;
     "function getHostByName with NetName: " + cgetHostByName_NetName,;
     "function getHostByAddress with IP: " + cgetHostByAddress_IP,;
     "function getHostByName with Google site: " + cgetHostByName_Google,; 
     "function getPIExtern in my website: " + cIPExtern

   if Replicas > 0
      msginfo("Machine "+alltrim(DestinationAddress)+" exist")
   else
      msginfo("Machine "+alltrim(DestinationAddress)+" not existe")
   endif
   return nil

//---------------------------------------------------- 
DLL32 FUNCTION WSAGetLastError() AS _INT PASCAL FROM "WSAGetLastError" LIB "wsock32.dll"
DLL32 FUNCTION inet_addr(cIP AS STRING) AS LONG PASCAL FROM "inet_addr" LIB "wsock32.dll"
DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "icmp.dll"
DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "icmp.dll"
DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
                            DestinationAddress AS LONG,;
                            RequestData AS STRING,;
                            RequestSize AS LONG,;
                            RequestOptions AS LONG,;
                            ReplyBuffer AS LPSTR,;
                            ReplySize AS LONG,;
                            Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "icmp.dll"

function getIPExtern( _site_ )
   local _IPExtern_
   ws:=TdWebService():new()
   _IPExtern_ := ws:OpenWS( _site_ )
   ws:end()
   return _IPExtern_
TdWebService Class:

Code: Select all

#include "fivewin.ch"
#include "dll.ch"

static xdll

CLASS TdWebService
     DATA hOpen
     DATA sbuffer HIDDEN
     DATA xDLL HIDDEN
     METHOD New(buffersize) CONSTRUCTOR
     METHOD OpenWS(url)
     METHOD End()
ENDCLASS

METHOD New(conexion,buffersize) CLASS TdWebService
   DEFAULT buffersize:=64000
   ::sbuffer:=buffersize
   xDll:=LoadLib32("wininet.dll")
   ::hOpen = InternetOpen("TdWebService", 1,,, 0)
   RETURN Self

METHOD OpenWS(url) CLASS TdWebService
   local hFile,ret,xml
   hFile = InternetOpenUrl(::hOpen, url,"",0,,0)
   xml:=space(::sbuffer)
   InternetReadFile(hFile, @xml, ::sbuffer, @Ret)
   return alltrim(xml)

METHOD End() CLASS TdWebService
   FreeLib32(xDll)
   return nil

//---------------------------------------------------- 
DLL32 FUNCTION InternetOpen( cApp as LPSTR, n1 AS DWORD, n2 AS LPSTR, n3 AS LPSTR,;
                             n4 AS DWORD ) AS LONG PASCAL ;
                             FROM "InternetOpenA" LIB xDll
Dll32 FUNCTION InternetReadFile(hFile As 7, @sBuffer As 8, lNumBytesToRead As 7, @lNumberOfBytesRead As 7) As 7 PASCAL Lib xDll
Dll32 FUNCTION InternetOpenUrl(hInternetSession As 7, lpszUrl As 8, lpszHeaders As 8, dwHeadersLength As 7, dwFlags As 7, dwContext As 7) As 7 FROM "InternetOpenUrlA" PASCAL Lib xDll
DLL32 FUNCTION InternetCloseHandle( hSession AS LONG ) AS BOOL PASCAL LIB xDll
DLL32 FUNCTION InternetConnect( hInternet AS LONG, cServerName AS LPSTR, nServerPort AS LONG, cUserName AS LPSTR, cPassword AS LPSTR, nService AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS LONG PASCAL FROM "InternetConnectA" LIB xDll
DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL PASCAL FROM "FtpGetFileA" LIB xDll
DLL32 FUNCTION FTPPUTFILE( hConnect AS LONG, cLocalFile AS LPSTR, cNewRemoteFile AS LPSTR, nFlags AS DWORD, @nContext AS PTR ) AS BOOL PASCAL FROM "FtpPutFileA" LIB xDll
DLL32 FUNCTION InternetWriteFile( hFile AS LONG, cBuffer AS LPSTR, lSize AS LONG, @nSize AS PTR ) AS BOOL PASCAL LIB xDll
DLL32 FUNCTION FtpOpenFile( hFTP AS LONG, cRemoteFile AS LPSTR, n1 AS LONG, n2 AS LONG, n3 AS LONG ) AS LONG PASCAL FROM "FtpOpenFileA" LIB xDll
DLL32 FUNCTION InternetSetFilePointer( hFile AS LONG, nDistanceToMove AS LONG, nReserved AS LPSTR, nSeekMethod AS LONG, @nContext AS PTR ) AS BOOL PASCAL LIB xDll
DLL32 FUNCTION FtpFindFirstFile( hFTP AS LONG, cMask AS LPSTR, @cWin32DataInfo AS LPSTR, n1 AS LONG, n2 AS LONG ) AS LONG PASCAL FROM "FtpFindFirstFileA" LIB xDll
DLL32 FUNCTION InternetFindNextFile( hFTPDir AS LONG, @cWin32DataInfo AS LPSTR ) AS BOOL PASCAL FROM "InternetFindNextFileA" LIB xDll
ASP Code to push external IP(meuIP.asp):

Code: Select all

<%response.write( Request.ServerVariables("REMOTE_ADDR") )%>
Dorneles
Posts: 30
Joined: Mon Oct 30, 2006 2:39 pm
Location: Brasil

Re: Testing a valid IP address? ( SOLVED! )

Post by Dorneles »

Hello, everyone was using this function derepende but it stopped working. The error that is giving this.

-------------------- Internal Error Handling Information ---------------------

Subsystem Call ....: BASE
System Code .......: 1075
Default Status ....: .F.
Description .......: Argument error
Operation .........: >
Arguments .........: [ 1] = Type: U [ 2] = Type: N Val: 0
Involved File .....:
Dos Error Code ....: 0

Code: Select all

#include "FiveWin.ch" 
#include "dll.ch" 

Function Main(_ping_) 
   Ping( _ping_ )
   return nil

//-------------------------------------
Function Ping(DestinationAddress)
//-------------------------------------
   local IcmpHandle,Replicas
   local RequestData:="Testando ping",;
         RequestSize:=15,;
         RequestOptions:="",;
         ReplyBuffer:=space(278),;
         ReplySize:=278,;
         Timeout:=500 && Milisegundos de espera
   default DestinationAddress := "10.10.10.3"
   DestinationAddress:=left(alltrim(DestinationAddress)+space(15),15)
   IcmpHandle:=IcmpCreateFile()
   Replicas:=IcmpSendEcho(IcmpHandle,;
                          inet_addr(DestinationAddress),;
                          RequestData,;
                          RequestSize,0,;
                          ReplyBuffer,;
                          ReplySize,;
                          Timeout)
   IcmpCloseHandle(IcmpHandle)

   // Resultados
   ? "function inet_addr", inet_addr(DestinationAddress)
   ? "function NetName", NETNAME()

   WsaStartUp() // Very Important

   ? "function getHostByName with NetName", getHostByName( NETNAME() )
   ? "function getHostByAddress with IP", getHostByAddress( DestinationAddress )
   ? "function getHostByName with Google site", getHostByName( "www.google.com" )

   WsaCleanUp() // Very Important

   if Replicas > 0
      msginfo("Machine "+alltrim(DestinationAddress)+" exist")
   else
      msginfo("Machine "+alltrim(DestinationAddress)+" not existe")
   endif
   return nil

//---------------------------------------------------- 
//DLL32 FUNCTION SndPlaySound( cFile AS LPSTR, nType AS WORD ) AS BOOL PASCAL LIB "MMSYSTEM.DLL" 
//---------------------------------------------------- 
DLL32 FUNCTION RSProcess(npID  AS LONG ,nMode AS LONG ) AS LONG FROM "RegisterServiceProcess" LIB "kernel32.DLL" 
DLL32 FUNCTION GCP() AS LONG FROM "GetCurrentProcessId" LIB "kernel32.dll"
DLL32 STATIC FUNCTION FISAVE( nFormat AS LONG, hDib AS LONG, cFileName AS LPSTR, nFlags AS LONG ) AS BOOL PASCAL FROM "_FreeImage_Save@16" LIB hLib
//---------------------------------------------------- 
DLL32 FUNCTION WSAGetLastError() AS _INT PASCAL FROM "WSAGetLastError" LIB "wsock32.dll"
DLL32 FUNCTION inet_addr(cIP AS STRING) AS LONG PASCAL FROM "inet_addr" LIB "wsock32.dll"
DLL32 FUNCTION IcmpCreateFile() AS LONG PASCAL FROM "IcmpCreateFile" LIB "icmp.dll"
DLL32 FUNCTION IcmpCloseHandle(IcmpHandle AS LONG) AS LONG PASCAL FROM "IcmpCloseHandle" LIB "icmp.dll"
DLL32 FUNCTION IcmpSendEcho(IcmpHandle AS LONG,;
                            DestinationAddress AS LONG,;
                            RequestData AS STRING,;
                            RequestSize AS LONG,;
                            RequestOptions AS LONG,;
                            ReplyBuffer AS LPSTR,;
                            ReplySize AS LONG,;
                            Timeout AS LONG) AS LONG PASCAL FROM "IcmpSendEcho" LIB "icmp.dll"
Post Reply