请问如何得到网线没擦好(网线断了)时网卡状态

chenpeng1234 2004-04-19 07:06:09
请各位大侠帮帮忙,哪为知道如何网线没擦好状态。我先谢谢大家了!
...全文
248 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
sevencat 2004-04-21
  • 打赏
  • 举报
回复
IOCTLSOCKET有个选项是SIO_GET_INTERFACE_LIST里面有个flags为IFF_UP(标志这个接口是否可用)

SIO_ADDRESS_LIST_CHANGE这个你也试试看,再不然,只有下基层去搞了。
zxq80 2004-04-21
  • 打赏
  • 举报
回复
1.你可测试是否和internet连着
2.ping台服务器
chenpeng1234 2004-04-21
  • 打赏
  • 举报
回复
up
暗黑帝国 2004-04-21
  • 打赏
  • 举报
回复
gz
辞多一撇 2004-04-21
  • 打赏
  • 举报
回复
我觉得,网卡驱动上面应该有这样的接口,你可以看看。不过要用到底层,我不喜欢!
beholder 2004-04-21
  • 打赏
  • 举报
回复
实时检测网线被拔掉是需要网卡设备驱动程序支持的,
如果驱动程序不支持是无法实现的,NDIS4要求设备驱动程序
最好提供CheckForHangHandler回调函数。2000会每隔2秒钟
调用此函数。驱动程序在此函数中检查网卡连线状态,
如果发生了改变,即拔去了网线或接上了网线,
驱动程序就会调用NdisMIndicateStatus通知所有的上层NDIS协议驱动程序.
其中: NDIS_STATUS_MEDIA_DISCONNECT 指示网线被拔掉,
NDIS_STATUS_MEDIA_CONNECT 指示网线被接上
NDIS_STATUS_LINK_SPEED_CHANGE 指示网卡速度改变,10/100自适应网卡才有。
网卡一般都有 status register 指示当然的连线状态,
也有网卡是通过获得 led status 来知道当前的连线状态的,
即绿灯亮表示连线,灭表示没有。
有些网卡拔掉或接上网线时会产生中断,在中断处理程序中一般也
检测网络连线状态并调用NdisMIndicateStatus,这样连线状态
在2000中就实时反应出来了,否则会在2秒钟内,即NDIS调用CheckForHangHandler后。



http://www.pcausa.com/resources/InetActive.txt
From: Allen Weng <yweg_spawa@microsoft.com>
Subject: RE: Detecting if internet connection is active at this moment.
Date: Friday, May 04, 2001 2:26 AM

Actually, there is no single function for determining if a machine is
connected to the Internet, and it is impossible to reliably determine what
is happening without side effects - such as automatic network connections
taking place. What you can do is reliably detect when there definitely
isn't an Internet Link: in the absence of any dial up or LAN connection the
system is definitely off line.

Some techniques include:

1. IsNetworkAlive()
If you are targeting system with IE5 or later, this is the best API call
yet it even listens for traffic on a LAN. There is a secondary function
IsDestinationReachable() which tries to resolve the hostname and ping it.
This does not work through firewalls, and overestimates speed as the max
the LAN card can support, rather than the actual point to point bandwidth.

2. RasEnumConnections()
A reliable technique for modems and direct dial up networking, but not for
situations where Internet access is via a LAN. You should dynamically load
"RasEnumConnectionA" from "RASAPI32.DLL", as LAN installations of Windows
may not include the library.

3. InternetGetConnectedState()
This Wininet /IE4 function call can distinguish between modem and LAN, but
can't handle complex LAN+autodial router situations. It is "offline state
aware". Important: handling of the offline flage changed for IE5 -it
returns TRUE for connected' even when off line, but signals the flags in
the LPDWORD parameter.

4. InternetCheckConnection()
A Winnet/IE4 function call. This is meant to determine if a URL is
reachable- in practice it is pretty unreliable and best voided.

5. NT SP4, NT5: The IP helper API can tell you which network interface to
use to connect to a supplied IP address, and what the bandwidth and current
status of that link is

6. Using the Offline flag which is part of IE4 to allow users to manually
control the online/offline state of applications. This flag is stored in
the registry and can be manipulated via some funcions calls

These calls mostly determine the presence or absence of network connections
-not Internet access, so can't handle a home network sharing a dial up
connection, or two laptops connected directly to each other.

The global offline state flag of IE4 (and hence win98, NT5) and the call to
test it - InternetGetConnectedState()- look the best long term options, but
will take time to become universal. The IP Helper APIs even let you find
out how much traffic is going over a link, but only detect the 'loopback'
interface on Windows 98, so is not a lot of use. Wouldn't a
'GetSpeedToHost() function call be great?

Finally, whatever technique you use, when it's time to talk to a remote
site, always add timeouts or a cancel button. Even a quick functions like
gethostbyname() can lock up an app if something in the network chain is
broken.

Allen Weng
Microsoft Developer Support

CWinApp *pApp = AfxGetApp();
top_hipster 2004-04-21
  • 打赏
  • 举报
回复
WSAConnect连接一个网站试试,如果返回WSAENETDOWN,差不多就是了
jxgcxy 2004-04-21
  • 打赏
  • 举报
回复
擦是什么?
Semigod 2004-04-21
  • 打赏
  • 举报
回复
这个东西据说只能通过驱动程序来获知
sharkhuang 2004-04-20
  • 打赏
  • 举报
回复
可能要硬件提供api编程才行.
chenpeng1234 2004-04-20
  • 打赏
  • 举报
回复
请各位大侠给点建议,也可,回复必有分!!!!!
doudou52520 2004-04-20
  • 打赏
  • 举报
回复
晕到呀!楼上的哥哥!



我帮你顶!
hudan 2004-04-20
  • 打赏
  • 举报
回复
要是干净的抹布擦了还不行,换一个水晶头 ^_^
elssann 2004-04-20
  • 打赏
  • 举报
回复
找块干净的抹布擦一下
PiggyXP 2004-04-20
  • 打赏
  • 举报
回复
友情up
chenpeng1234 2004-04-20
  • 打赏
  • 举报
回复
up
chenpeng1234 2004-04-20
  • 打赏
  • 举报
回复
up
chenpeng1234 2004-04-19
  • 打赏
  • 举报
回复
是的,我查了半天MSDN没有发现相关的API
请各位大侠帮帮忙,告诉小弟一下。谢谢了
GoldenSword 2004-04-19
  • 打赏
  • 举报
回复
Win2K自己就知道,可以看看他怎么做的

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧