找回密码
 加入
搜索
楼主: fuinei

[网络通信] [已解决]判断PC能否访问Internet

 火.. [复制链接]
 楼主| 发表于 2012-3-29 11:18:38 | 显示全部楼层
回复 15# calora88
谢谢指导,这种方法实际与telnet效果相同,在我司的环境中即使不能访问指定的站点,但是ping,telnet到80端口还是可以的,因此这种方法适用于一般的环境但不适用于我目前的情况.
发表于 2012-3-29 13:19:55 | 显示全部楼层
试试xmlhttp看看返回什么错误
 楼主| 发表于 2012-3-29 13:31:36 | 显示全部楼层
回复 17# auto
请问xmlhttp指的是哪个函数,第三方UDF吗?
发表于 2012-3-29 13:41:22 | 显示全部楼层
楼主这个问题没说清楚吧,指的是外网还是内网,外网的话直接ping个域名就行了,内网的话,检查四个'端口'
 楼主| 发表于 2012-3-29 13:57:36 | 显示全部楼层
回复 19# netegg
我的问题是检查外网,公司的PC只要开机是一直连接的,但访问外网则需经代理服务器,代理服务器上有针对不同级别帐号的策略,部分帐号可能被禁止访问大部分网址但ping和telnet到80端口都是可以的.
发表于 2012-3-29 14:23:59 | 显示全部楼层
2003?不太会玩了
 楼主| 发表于 2012-3-29 18:25:36 | 显示全部楼层
回复 21# netegg
不是的,代理服务器是硬件代理,一般的PC是XP的
发表于 2012-3-29 18:36:52 | 显示全部楼层
和我们公司是一样,你要在代理服务器上下工夫
判断PC,你要先判断登陆的账户不是?除非人手一台电脑
 楼主| 发表于 2012-3-29 18:41:39 | 显示全部楼层
回复 23# 502762378
看来只有14楼的方法(使用InetGet根据下载的内容)来判断用户能否访问Intenet了
发表于 2012-3-29 18:47:02 | 显示全部楼层
恩判断回执当然可以,虽然笨了点,其实这个问题没有意义,代理服务器有很多功能你自己琢磨呗
发表于 2012-3-29 18:51:50 | 显示全部楼层
标记一下
标记一下
 楼主| 发表于 2012-3-30 08:30:48 | 显示全部楼层
谢谢各位的回复,此帖先标记为已解决,如有问题方法的可以继续跟贴
发表于 2012-3-30 10:19:20 | 显示全部楼层
不想要暫存檔 剩winhttp了
udf 在
http://winhttp.origo.ethz.ch/download
#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; Initialize
Global $hOpen = _WinHttpOpen()

If @error Then
    MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
    Exit 1
EndIf

; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen, "www.163.com") ; <- yours here
If @error Then
    MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
    _WinHttpCloseHandle($hOpen)
    Exit 2
EndIf

; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect)
If @error Then
    MsgBox(48, "Error", "Error creating an HTTP request handle.")
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 3
EndIf

; Send it
_WinHttpSendRequest($hRequest)
If @error Then
    MsgBox(48, "Error", "Error sending specified request.")
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 4
EndIf

; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
    MsgBox(48, "Error", "Error waiting for the response from the server.")
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 5
EndIf

; See if there is data to read
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
    ; Read
    While 1
        $sChunk = _WinHttpReadData($hRequest)
        If @error Then ExitLoop
        $sData &= $sChunk
    WEnd
;    ConsoleWrite($sData & @CRLF) ; print to console
MsgBox(0,1,$sData)
Else
    MsgBox(48, "Error", "Site is experiencing problems.")
EndIf

; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)

评分

参与人数 1金钱 +20 收起 理由
afan + 20

查看全部评分

 楼主| 发表于 2012-3-30 11:11:10 | 显示全部楼层
本帖最后由 fuinei 于 2012-3-30 11:12 编辑

回复 28# calora88

谢谢指导,代码返回访问页面的内容,该方法仍需判断返回内容才能确定当前帐号在PC上能否访问Internet,使用以下代码时遇到不能准确判断结果,不知道是否由于内容太多导致变量$sData无法存放所有的内容导致的呢?
#include "WinHttp.au3"

Opt("MustDeclareVars", 1)

; Initialize
Global $hOpen = _WinHttpOpen()

If @error Then
    MsgBox(48, "Error", "Error initializing the usage of WinHTTP functions.")
    Exit 1
EndIf

; Specify what to connect to
Global $hConnect = _WinHttpConnect($hOpen, "www.baidu.com") ; <- yours here
If @error Then
    MsgBox(48, "Error", "Error specifying the initial target server of an HTTP request.")
    _WinHttpCloseHandle($hOpen)
    Exit 2
EndIf

; Create request
Global $hRequest = _WinHttpOpenRequest($hConnect)
If @error Then
    MsgBox(48, "Error", "Error creating an HTTP request handle.")
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 3
EndIf

; Send it
_WinHttpSendRequest($hRequest)
If @error Then
    MsgBox(48, "Error", "Error sending specified request.")
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 4
EndIf

; Wait for the response
_WinHttpReceiveResponse($hRequest)
If @error Then
    MsgBox(48, "Error", "Error waiting for the response from the server.")
    _WinHttpCloseHandle($hRequest)
    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
    Exit 5
EndIf

; See if there is data to read
Global $sChunk, $sData
If _WinHttpQueryDataAvailable($hRequest) Then
    ; Read
    While 1
        $sChunk = _WinHttpReadData($hRequest)
        If @error Then ExitLoop
        $sData &= $sChunk
    WEnd
;    ConsoleWrite($sData & @CRLF) ; print to console
;MsgBox(0,1,$sData)
        If StringInStr($sData,"Note: Please have your identity authenticated before accessing the Internet。",1) > 0 Then
                MsgBox(48,"Error","请登陆代理服务器")
        ElseIf StringInStr($sData,"http://192.168.1.254/disable/disable.htm",1) >0 then
                MsgBox(48,"Error","当前帐号不允许访问Internet")
        Else
                MsgBox(0,"Info","当前帐号可以访问Internet")
        EndIf
Else
    MsgBox(48, "Error", "Site is experiencing problems.")
EndIf

; Close handles when they are not needed any more
_WinHttpCloseHandle($hRequest)
_WinHttpCloseHandle($hConnect)
_WinHttpCloseHandle($hOpen)
发表于 2012-3-30 12:08:49 | 显示全部楼层
Local $fid=FileOpen("a.txt", 16)
Local $data=FileRead($fid)
If @error Then MsgBox(0,1,'error')
FileClose($fid)
$fid=FileOpen("b.txt", 16 + 2)
FileWrite($fid, $data)
FileClose($fid)
Exit
用此代碼測試250m的檔案是ok的, 你的網頁不會超過250m吧
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-16 23:54 , Processed in 0.079604 second(s), 18 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表