[Mono-dev] Testing if there is a network connection or not

"C. Bergström" cbergstrom at netsyncro.com
Fri Feb 9 06:16:39 EST 2007


Paul wrote:
> Hi,
>
> I'm currently using System.Management.ManagementObjectSearcher on VS.NET
> to check if there is a network connection or not. This looks to be
> implemented under Win32 but dead under Linux.
>
> Is there another way to check if there is a connection or not without
> using S.M.ManagementObjectSearcher?
This may not be what you're looking for, but

ST_NET=`ifconfig $IF | grep inet | cut -d : -f 2 | cut -d \  -f 1`
TT_NET=`tail -n 15 $SYSLOG | grep -wi "$IF: transmit timed out"`

This is using the linux ifconfig way of doing it.  I can also dig out 
the ip way of doing it as well.. Which may be more portable iirc.

Another alternative could be to use arping and test for a response from 
the gw.. I'm not sure exactly sure how M$ defines if the interface is 
up.. or active or has a valid gw.. etc...

C.



More information about the Mono-devel-list mailing list