Network cable unplugged

Posted: 08-11-2004, 06:12 PM
I need to be able to determine if the network cable is unplugged. I've been
through various news groups and the MS API, and cannot find anything. I
have a headless device, so I have network setup happening on a non-desktop
interface. I need to be able to determine the difference between
000.000.000.000 as not set up yet, and 000.000.000.000 as no cable plugged
in. DHCP may or may not be present (one possible user configuration would
be two users connected with a crossover cable and manual IP's).

Thanks,

Greg


Network cable unplugged


Reply With Quote

Responses to "Network cable unplugged"

Greg Brown
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 08:01 PM
well if any one is interested... I finally found what I needed in
GetIfEntry()


Reply With Quote
Sean Gahan
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 08:06 PM
Greg,
I would try a script something like this:

do
strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =
True")
For Each objAdapter in colAdapters
If Not IsNull(objAdapter.IPAddress) Then
For i = LBound(objAdapter.IPAddress) To
UBound(objAdapter.IPAddress)
if objAdapter.IPAddress(i) = "" then
Wscript.Echo "Dude: you network cable is unplugged." & vbcrlf & _
"Description: " & objAdapter.Description & vbcrlf & _
"IP address: " & objAdapter.IPAddress(i)
End if
Next
End If
next
Wscript.Sleep 1000
loop

Regards,

Sean Gahan


"Greg Brown" <abc@123.com> wrote in message
news:%23LZPL78fEHA.592@TK2MSFTNGP11.phx.gbl...
> I need to be able to determine if the network cable is unplugged. I've
been
> through various news groups and the MS API, and cannot find anything. I
> have a headless device, so I have network setup happening on a non-desktop
> interface. I need to be able to determine the difference between
> 000.000.000.000 as not set up yet, and 000.000.000.000 as no cable plugged
> in. DHCP may or may not be present (one possible user configuration would
> be two users connected with a crossover cable and manual IP's).
>
> Thanks,
>
> Greg
>
>

Reply With Quote
KM
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 08:23 PM
Greg,

Or use GetAdaptersInfo/GetInterfaceInfo APIs. Just more info provided.

--
Regards,
KM, BSquare Corp.

> well if any one is interested... I finally found what I needed in
> GetIfEntry()
>
>

Reply With Quote
Doug Hoeffel
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 08:32 PM
Sean:

How about this:

Function GetLinkStatus()

Dim queryString
Set WMILinkInterface = WMIInterface.ConnectServer(".", "Root\wmi", "", "")

queryString = "select * from MSNdis_MediaConnectStatus where InstanceName =
'"
queryString = queryString & top.netAdapterName & "'"

Set mediaCollection = WMILinkInterface.ExecQuery(queryString)

For Each ObjItem In mediaCollection
GetLinkStatus = ObjItem.NdisMediaConnectStatus
Next
End Function

where top.netAdapterName would need to be set for your NIC adapter name.

HTH... Doug
"Sean Gahan" <sean@optistreams.net> wrote in message
news:%23zHJL$9fEHA.3048@TK2MSFTNGP09.phx.gbl...
> Greg,
> I would try a script something like this:
>
> do
> strComputer = "."
> Set objWMIService = GetObject _
> ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
> Set colAdapters = objWMIService.ExecQuery _
> ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =
> True")
> For Each objAdapter in colAdapters
> If Not IsNull(objAdapter.IPAddress) Then
> For i = LBound(objAdapter.IPAddress) To
> UBound(objAdapter.IPAddress)
> if objAdapter.IPAddress(i) = "" then
> Wscript.Echo "Dude: you network cable is unplugged." & vbcrlf &
_
> "Description: " & objAdapter.Description & vbcrlf & _
> "IP address: " & objAdapter.IPAddress(i)
> End if
> Next
> End If
> next
> Wscript.Sleep 1000
> loop
>
> Regards,
>
> Sean Gahan
>
>
> "Greg Brown" <abc@123.com> wrote in message
> news:%23LZPL78fEHA.592@TK2MSFTNGP11.phx.gbl...
> > I need to be able to determine if the network cable is unplugged. I've
> been
> > through various news groups and the MS API, and cannot find anything. I
> > have a headless device, so I have network setup happening on a
non-desktop
> > interface. I need to be able to determine the difference between
> > 000.000.000.000 as not set up yet, and 000.000.000.000 as no cable
plugged
> > in. DHCP may or may not be present (one possible user configuration
would
> > be two users connected with a crossover cable and manual IP's).
> >
> > Thanks,
> >
> > Greg
> >
> >
>
>

Reply With Quote
Greg Brown
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 08:44 PM
Thanks for the responses...

I am enumerating thru GetAdaptersInfo(), but that wasn't telling me anything
except that the IP was not set. Using the index member returned from
GetAdaptersInfo() in GetIfEntry() will give you dwOperStatus something other
than MIB_IF_OPER_STATUS_OPERATIONAL when the cable is unplugged.


Reply With Quote
KM
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 09:00 PM
Greg,

Could be.. I've heard of some problems with dwOperStatus return from GetIfEntry.

You can also check out WinDDK code under \src\setup\enable. This may be of some help to you.

--
Regards,
KM, BSquare Corp.

> Thanks for the responses...
>
> I am enumerating thru GetAdaptersInfo(), but that wasn't telling me anything
> except that the IP was not set. Using the index member returned from
> GetAdaptersInfo() in GetIfEntry() will give you dwOperStatus something other
> than MIB_IF_OPER_STATUS_OPERATIONAL when the cable is unplugged.
>
>

Reply With Quote
Lasse
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 09:03 PM
Greg Brown wrote:
> I need to be able to determine if the network cable is unplugged. I've been
> through various news groups and the MS API, and cannot find anything. I
> have a headless device, so I have network setup happening on a non-desktop
> interface. I need to be able to determine the difference between
> 000.000.000.000 as not set up yet, and 000.000.000.000 as no cable plugged
> in. DHCP may or may not be present (one possible user configuration would
> be two users connected with a crossover cable and manual IP's).
>
> Thanks,
>
> Greg
>
>
Write a C program and ...
Use API: GetIfTable(pIfTable, &Size, FALSE);
Then look at: pIfTable->table[i].dwOperStatus
Reply With Quote
Sean Gahan
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 09:08 PM
Doug,
I wonder how many different ways this can be done. How about one more:

do
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
Set objShell = WScript.CreateObject("WScript.Shell")
Set objExecObject = objShell.Exec("cmd /c ping " &
IPConfig.IPAddress(i) )
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadLine()
If Instr(strText, "Reply") > 0 Then
Wscript.Echo "Reply received from " & IPConfig.IPAddress(i)
Exit Do
End If
Loop
Next
End If
Next
Wscript.Sleep 1000
loop

Regards,

Sean Gahan



"Doug Hoeffel" <doug.hoeffelNo@SpAmMcamtronics.com> wrote in message
news:emQxLJ%23fEHA.644@tk2msftngp13.phx.gbl...
> Sean:
>
> How about this:
>
> Function GetLinkStatus()
>
> Dim queryString
> Set WMILinkInterface = WMIInterface.ConnectServer(".", "Root\wmi", "",
"")
>
> queryString = "select * from MSNdis_MediaConnectStatus where InstanceName
=
> '"
> queryString = queryString & top.netAdapterName & "'"
>
> Set mediaCollection = WMILinkInterface.ExecQuery(queryString)
>
> For Each ObjItem In mediaCollection
> GetLinkStatus = ObjItem.NdisMediaConnectStatus
> Next
> End Function
>
> where top.netAdapterName would need to be set for your NIC adapter name.
>
> HTH... Doug
> "Sean Gahan" <sean@optistreams.net> wrote in message
> news:%23zHJL$9fEHA.3048@TK2MSFTNGP09.phx.gbl...
> > Greg,
> > I would try a script something like this:
> >
> > do
> > strComputer = "."
> > Set objWMIService = GetObject _
> > ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
> > Set colAdapters = objWMIService.ExecQuery _
> > ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled =
> > True")
> > For Each objAdapter in colAdapters
> > If Not IsNull(objAdapter.IPAddress) Then
> > For i = LBound(objAdapter.IPAddress) To
> > UBound(objAdapter.IPAddress)
> > if objAdapter.IPAddress(i) = "" then
> > Wscript.Echo "Dude: you network cable is unplugged." & vbcrlf
&
> _
> > "Description: " & objAdapter.Description & vbcrlf & _
> > "IP address: " & objAdapter.IPAddress(i)
> > End if
> > Next
> > End If
> > next
> > Wscript.Sleep 1000
> > loop
> >
> > Regards,
> >
> > Sean Gahan
> >
> >
> > "Greg Brown" <abc@123.com> wrote in message
> > news:%23LZPL78fEHA.592@TK2MSFTNGP11.phx.gbl...
> > > I need to be able to determine if the network cable is unplugged.
I've
> > been
> > > through various news groups and the MS API, and cannot find anything.
I
> > > have a headless device, so I have network setup happening on a
> non-desktop
> > > interface. I need to be able to determine the difference between
> > > 000.000.000.000 as not set up yet, and 000.000.000.000 as no cable
> plugged
> > > in. DHCP may or may not be present (one possible user configuration
> would
> > > be two users connected with a crossover cable and manual IP's).
> > >
> > > Thanks,
> > >
> > > Greg
> > >
> > >
> >
> >
>
>

Reply With Quote
Doug Hoeffel
Guest
Posts: n/a
 
Re: Network cable unplugged
Posted: 08-11-2004, 09:15 PM
cool... go old ping ;-)

"Sean Gahan" <sean@optistreams.net> wrote in message
news:egyzFf%23fEHA.3192@tk2msftngp13.phx.gbl...
> Doug,
> I wonder how many different ways this can be done. How about one more:
>
> do
> strComputer = "."
> Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
> Set IPConfigSet = objWMIService.ExecQuery _
> ("Select * from Win32_NetworkAdapterConfiguration where
IPEnabled=TRUE")
> For Each IPConfig in IPConfigSet
> If Not IsNull(IPConfig.IPAddress) Then
> For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
> Set objShell = WScript.CreateObject("WScript.Shell")
> Set objExecObject = objShell.Exec("cmd /c ping " &
> IPConfig.IPAddress(i) )
> Do While Not objExecObject.StdOut.AtEndOfStream
> strText = objExecObject.StdOut.ReadLine()
> If Instr(strText, "Reply") > 0 Then
> Wscript.Echo "Reply received from " & IPConfig.IPAddress(i)
> Exit Do
> End If
> Loop
> Next
> End If
> Next
> Wscript.Sleep 1000
> loop
>
> Regards,
>
> Sean Gahan
>
>
>
> "Doug Hoeffel" <doug.hoeffelNo@SpAmMcamtronics.com> wrote in message
> news:emQxLJ%23fEHA.644@tk2msftngp13.phx.gbl...
> > Sean:
> >
> > How about this:
> >
> > Function GetLinkStatus()
> >
> > Dim queryString
> > Set WMILinkInterface = WMIInterface.ConnectServer(".", "Root\wmi", "",
> "")
> >
> > queryString = "select * from MSNdis_MediaConnectStatus where
InstanceName
> =
> > '"
> > queryString = queryString & top.netAdapterName & "'"
> >
> > Set mediaCollection = WMILinkInterface.ExecQuery(queryString)
> >
> > For Each ObjItem In mediaCollection
> > GetLinkStatus = ObjItem.NdisMediaConnectStatus
> > Next
> > End Function
> >
> > where top.netAdapterName would need to be set for your NIC adapter name.
> >
> > HTH... Doug
> > "Sean Gahan" <sean@optistreams.net> wrote in message
> > news:%23zHJL$9fEHA.3048@TK2MSFTNGP09.phx.gbl...
> > > Greg,
> > > I would try a script something like this:
> > >
> > > do
> > > strComputer = "."
> > > Set objWMIService = GetObject _
> > > ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
> > > Set colAdapters = objWMIService.ExecQuery _
> > > ("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled
=
> > > True")
> > > For Each objAdapter in colAdapters
> > > If Not IsNull(objAdapter.IPAddress) Then
> > > For i = LBound(objAdapter.IPAddress) To
> > > UBound(objAdapter.IPAddress)
> > > if objAdapter.IPAddress(i) = "" then
> > > Wscript.Echo "Dude: you network cable is unplugged." &
vbcrlf
> &
> > _
> > > "Description: " & objAdapter.Description & vbcrlf & _
> > > "IP address: " & objAdapter.IPAddress(i)
> > > End if
> > > Next
> > > End If
> > > next
> > > Wscript.Sleep 1000
> > > loop
> > >
> > > Regards,
> > >
> > > Sean Gahan
> > >
> > >
> > > "Greg Brown" <abc@123.com> wrote in message
> > > news:%23LZPL78fEHA.592@TK2MSFTNGP11.phx.gbl...
> > > > I need to be able to determine if the network cable is unplugged.
> I've
> > > been
> > > > through various news groups and the MS API, and cannot find
anything.
> I
> > > > have a headless device, so I have network setup happening on a
> > non-desktop
> > > > interface. I need to be able to determine the difference between
> > > > 000.000.000.000 as not set up yet, and 000.000.000.000 as no cable
> > plugged
> > > > in. DHCP may or may not be present (one possible user configuration
> > would
> > > > be two users connected with a crossover cable and manual IP's).
> > > >
> > > > Thanks,
> > > >
> > > > Greg
> > > >
> > > >
> > >
> > >
> >
> >
>
>

Reply With Quote
 
LinkBack Thread Tools Display Modes
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


Similar Threads
Thread Thread Starter Forum Replies Last Post
Network Cable is Unplugged Unplugged Windows XP Work Remotely 1 04-04-2004 01:56 PM
network cable unplugged Ramchand Windows XP Network & Web 37 03-01-2004 10:56 PM
network cable is unplugged travis Windows XP Network & Web 23 01-28-2004 08:32 AM
network cable unplugged Forrest G. Windows XP Help & Support 7 11-13-2003 10:44 AM
a network cable is unplugged charlie Windows XP Network & Web 12 11-11-2003 05:48 AM