Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Check if WAN machine is online before connecting

Posted on 2013-11-02
2
359 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 42

Expert Comment

by:pcelba
ID: 39618950
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 42

Accepted Solution

by:
pcelba earned 500 total points
ID: 39618971
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Most MSPs worth their salt are already offering cybersecurity to their customers. But cybersecurity as a service is wide encompassing and can mean many things.  So where are MSPs falling in this spectrum?
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

792 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