Solved

Need network connection advice

Posted on 2004-10-05
7
164 Views
Last Modified: 2010-04-23
I created a class:


Public Class NetworkStatus
    Dim online

    Public Property Netstatus()
        Get
            Call Online_Offline()
            Return online
        End Get
        Set(ByVal Value)
            online = Value
        End Set
    End Property

    Public Sub Online_Offline()
        '  Dim online
        Dim DriveLetter As String
        Dim AllDrives As New ArrayList
        For Each DriveLetter In IO.Directory.GetLogicalDrives()
            Console.WriteLine(DriveLetter)
            AllDrives.Add(DriveLetter.Substring(0, 1))
        Next
        On Error Resume Next

        If Not AllDrives.Contains("Z") Then
            Dim net
            net = CreateObject("WScript.Network")
            net.MapNetworkDrive("Z:", "\\winn\gssectssec")

        End If
        If AllDrives.Contains("Z") Then
            online = True
        Else
            online = False
        End If

    End Sub
End Class


However, I call on this class everytime to determine which database im going to connect.  I am finding out that if i connected, then went offline, MY Z: is still active.


My question is:

Is there a way to check the network status and get a return value back, such as

If ping http:www.yahoo.com successful Then
bla bla
else
bla bla

Or any other suggestions
0
Comment
Question by:malanois
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:eozz_2000
Comment Utility
Jejeje... I have a not very useful way... I do a FTP to the server with this command:

Shell("FTP -s:Command.dat", AppWindowStyle.Hide, True, 5000)

in Command.dat I have the commands needed to get the file:

open
my_server
my_user
my_password
get
remote_file
local_file_path_to_store_it
bye

and then, I check if the file exists after the ftp has finished his execution.  Obviously the file is 1 byte long., and I try to delete it when the program starts.
0
 
LVL 5

Expert Comment

by:naiea1231
Comment Utility
I use this in one of my scripts:

'leave this as it is, represents where the ping originates
sHost            = "."

'change this to the ip or url of where you want to ping
sClient = "yahoo.com"

Set cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
            sHost & "/root/cimv2"). ExecQuery("SELECT * FROM Win32_PingStatus " & _
            "WHERE Address = '" + sClient + "'")

'process ping results
For Each oPingResult In cPingResults
      If oPingResult.StatusCode = 0 Then
            WScript.Echo sClient & " is responding"
                  Else
            WScript.Echo sClient & " is not responding"
      End If
Next



Give that a try, seems to be what your looking for.
James
0
 

Author Comment

by:malanois
Comment Utility
JAMES

That is what I am looking for, I will give it a try and lwt you know.'


Thanks

malanois
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:malanois
Comment Utility
James,

I must not be declaring something correctly.

It will not allow the set command  ..      Set cPingResul   ----- It keeps taking Set away


 Dim shost, sClient
        Dim cPingResults
        Dim oPingResult As Object

what am I missing here



0
 
LVL 5

Expert Comment

by:naiea1231
Comment Utility
Ahh, since your using vb.net there is not need to use set, as the above script was originally written in vbscript. Just allow it to remove the set, and it should be fine. Let me know it goes.

James
0
 

Author Comment

by:malanois
Comment Utility
man o man am i having issues:

  Dim shost, sClient
        Dim cPingResults
        Dim oPingResult As Object

        Dim WScript

        shost = "."

        'change this to the ip or url of where you want to ping
        sClient = "yahoo.com"

       cPingResults = GetObject("winmgmts:{impersonationLevel=impersonate}//" & _
                      shost & "/root/cimv2").ExecQuery("SELECT * FROM Win32_PingStatus " & _
                 "WHERE Address = '" + sClient + "'")

        'process ping results
        For Each oPingResult In cPingResults
            If oPingResult.StatusCode = 0 Then
                WScript.Echo(sClient & " is responding")  <<<<<<<<<<<<<
            Else
                WScript.Echo(sClient & " is not responding")<<<<<<<<<<<<  WScript has no object set error
            End If
        Next

I have tried creating variables,
setiing things to objects like above:  It still will not run?????????


This is what Im looking for just need to get it to work



0
 
LVL 5

Accepted Solution

by:
naiea1231 earned 500 total points
Comment Utility
Ahh, don't worry about the wscript.echo, its just a way to use vbscript to report back

You can just change that to

MsgBox(sClient & " is responding")
and
MsgBox(sClient & " is not responding")

However, those lines are only used to report back whether the ping was successful or not. If you want to make use of the input its probably best to replace that with variables such as, when it responds:
PingSuccess = 1

And when it fails
PingSuccess = 0

You can then use this result later on, or return the value when you call the function etc.

If you have any further questions, don't hesitate to ask

James

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

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

6 Experts available now in Live!

Get 1:1 Help Now