Solved

Check if WAN machine is online before connecting

Posted on 2013-11-02
2
356 Views
Last Modified: 2013-11-04
Hi Expert
I use the following code to connect to a server on WAN using ipaddress.

lcStr = "Driver={SQL SERVER};Server=&SERVERIP;Database=Auto;UID=myname;pwd=mypass;Trusted_Connection=no;"
lnHandle = Sqlstringconnect(lcStr)
If lnHandle>=1
      lnResult = SQLExec(lnHandle, "SELECT * FROM loged ", "cOutData2")
endif

it works fine,but if the server is off line it takes a long time to come back.

Is there any way I can check this ipaddress machine is online before trying to get the information?
Thanks
0
Comment
Question by:b001
  • 2
2 Comments
 
LVL 41

Expert Comment

by:pcelba
Comment Utility
You may use following code (source: www.News2news.com):
DO declare
 
LOCAL nDst, nHop, nRTT
nDst = inet_addr("217.198.114.255")  && celba.cz
 
STORE 0 TO nHop, nRTT
 
IF GetRTTAndHopCount(nDst, @nHop, 50, @nRTT) <> 0
    ? "Hop count to the destination:", nHop
    ? "Round-trip time, in milliseconds:", nRTT
ELSE
* on error, GetLastError may still return zero
    ? "Error"
ENDIF
* end of main
 
PROCEDURE declare
    DECLARE INTEGER GetRTTAndHopCount IN Iphlpapi;
        INTEGER DestIpAddress, LONG @HopCount,;
        INTEGER MaxHops, LONG @RTT
 
    DECLARE INTEGER inet_addr IN ws2_32 STRING cp

Open in new window

but it also takes time when you are not connected...
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
Comment Utility
This seems to be faster (WMI has not so long timeout):
oWMI = getobject("winmgmts:")
cAddress = "127.0.0.1" && Or host name

oPings = oWMI.ExecQuery([Select * from WIN32_Pingstatus where address='] + cAddress + ['])

for each oPing in oPings
  ? oPing.ProtocolAddress
  IF oPing.statuscode = 0
    ?? " Connected"
  ELSE
    ?? " Not accessible"
  ENDIF
NEXT

Open in new window


Source: http://www.foxite.com/archives/network-or-ip-address-status-0000115274.htm
This page also lists many possible Status codes so you may inform user what's possibly wrong.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now