主题:还是关于InterNet
homayzh
[专家分:7040] 发布于 2009-01-24 13:47:00
如果测试是否联接internet?
Declare SHORT InternetGetConnectedStateEx IN wininet.dll INTEGER @ lpdwFlags, STRING @ lpszConnectionName, INTEGER dwNameLen,INTEGER dwReserved
lpdwFlags = 0
lcConnection = REPLI (Chr(0), 250)
If InternetGetConnectedStateEx (@lpdwFlags, @lcConnection, Len(lcConnection), 0) = 1
yzh = lcconnection
Endif
IF yzh = "宽带连接"
messagebox(连接成功)
else
.....
endif
这个好像是测试本地联接是否连接,如果在dos下可以用
ping www.baidu.com,
在vfp下有类似的方法吗?
回复列表 (共2个回复)
沙发
wuzhouhong [专家分:10890] 发布于 2009-01-29 23:10:00
?domain2ip("www.shonline.sh.cn") && 75.126.238.193
?domain2ip("www.shonline123.sh.cn") && .NULL.
**** 域名转换为IP地址
**** 来自http://www.gz9f.com/
**** 域名Ping不通,就返回NULL值
**** domain2ip.prg
#DEFINE NULL_IP .NULL.
#DEFINE HOSTENT_SIZE 16
PARAMETERS cDOMAIN
LOCAL cResult
IF VARTYPE(m.cDOMAIN)="C"
DECLARE INTEGER WSACleanup IN ws2_32
DECLARE STRING inet_ntoa IN ws2_32 INTEGER in_addr
DECLARE INTEGER gethostbyname IN ws2_32 STRING host
DECLARE INTEGER WSAStartup IN ws2_32 INTEGER wVerRq, STRING lpWSAData
DECLARE RtlMoveMemory IN kernel32 As CopyMemory STRING @Dest, INTEGER Src, INTEGER nLength
IF WSAStartup(0x202, Repli(Chr(0),512)) = 0 && initiates use of WS2_32.DLL
m.cResult = GetIP(m.cDOMAIN)
=WSACleanup()
ELSE
m.cResult = NULL_IP
ENDIF
ELSE
m.cResult = NULL_IP
ENDIF
RETURN m.cResult
*** returns IP like 127.0.0.1 for a given host name like www.somewhere.com
FUNCTION GetIP(cServer)
LOCAL nStruct, nSize, cBuffer, nAddr, cIP
m.nStruct = gethostbyname(m.cServer)
IF m.nStruct = 0 && not found in a host database; or not connected etc.
RETURN NULL_IP
ENDIF
m.cBuffer = Repli(Chr(0), HOSTENT_SIZE)
m.cIP = Repli(Chr(0), 4)
= CopyMemory(@cBuffer, m.nStruct, HOSTENT_SIZE)
= CopyMemory(@cIP, buf2dword(SUBS(m.cBuffer,13,4)),4)
= CopyMemory(@cIP, buf2dword(m.cIP),4)
RETURN inet_ntoa(buf2dword(m.cIP))
FUNCTION buf2dword(lcBuffer)
RETURN Asc(SUBSTR(m.lcBuffer, 1,1)) + ;
Bitlshift(Asc(SUBS(m.lcBuffer, 2,1)),8) +;
Bitlshift(Asc(SUBS(m.lcBuffer, 3,1)),16) +;
Bitlshift(Asc(SUBS(m.lcBuffer, 4,1)),24)
板凳
homayzh [专家分:7040] 发布于 2009-02-05 21:39:00
谢谢,楼上,还有其它方法吗?
我记得cbl518老师 曾经有一个api函数就可以,
可是我不知道是什么 了....
我来回复