Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

check for network connection - SLOW!

Status
Not open for further replies.

Pudsters

Technical User
Mar 16, 2006
151
US
I modified this from an Internet Search. It tests to see if the user is connected to a company network. It works, but the first time I run it, whether connected to network or not, it takes about 27 seconds - VERY SLOW! Then each time, it is almost instant. Anyway to speed the initial runtime up?

Code:
Sub checkmynetwork()
 
Set objFSO = CreateObject("Scripting.FileSystemObject")

    If objFSO.FolderExists("\\24.224.224.224\DATA\HOME") Then    
            MsgBox "Connected to network, Use Internal IP Address"      
    Else    
            MsgBox "Not connected to network, Use External IP Address"         
         
    End If


End Sub

I've also tried this, which seems to do a little better, but still long delay on first attempt:

Code:
Sub checkmynetwork2()

    Dim FSO As Scripting.FileSystemObject
    Dim FolderPath As String

    Set FSO = New Scripting.FileSystemObject

    FolderPath = "F:\HOME\"
    If Right(FolderPath, 1) <> "\" Then
        FolderPath = FolderPath & "\"
    End If

    If FSO.FolderExists(FolderPath) = False Then
        MsgBox "Not connected to network, Use External IP Address"
    Else
        MsgBox "Connected to network, Use Internal IP Address"
    End If

End Sub
 
I see your problem. Your LAN server is in a routable IP range. That is the internal IP of your server (24.224.224.224) is routable on the internet. IP's that begin "10." or "192.168." are not routable and common for small office Lan's. Bigger networks can't do this and instead use a proxy server to get to the Internet. Out of the office, your computer is likely trying to bug some computer on the Internet for information. So all that said, I think your method is fundamentally flawed for your circumstance.

That said I do not have a good answer. Anything that tries to reach an unreachable network is going to take time to fail.

You want something that has a quick response, and something there is an example of how to do that via VBA. I briefly thought setting an environment variable during logon and checking with environ() would work but then I realized it would stay set until boot which could be AFTER a disconnect. You could maybe check such a variable first and then only do a long to fail test if set (find something that is not a bad Internet citizen). It may speed things up in some/most cases. If that works, you need IT to do something at logon or give you a value you can check. Likely they won't add something but maybe there is something you can check.

Maybe you could do a direct DNS lookup to your server name somehow via vba? It had better use a fully qualified domain name that your company owns the root domain for or you could end up in a spoofing situation.

Anyway if you solve it with this nudge in the right direction, let us know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top