1

Konu: İnternet bağlantısının kontrolünde sorun

Merhaba,
İnternet bağlantısının olup olmadığın kontrol etmek için aşağıdaki kodu kullanıyorum; ancak denemelerim sırasında bu kod doğru çalışmadığını farkettim yardım ederseniz sevinirim.

Bilgisayarım internete bağlıyken fonksiyon bağlı olduğuna dair doğru sonuç gönderiyor. Programdan çıkmadan bilgisayarımın ağ bağlantı kablosunu çıkartıp internet bağlantımı sonlandırdırdığımda fonksiyon hala internet bağlantısı olduğunu söylüyor. Bu sorunu çözmek için Clear Dlls komutunu kullandım. Bu komut bazen işimi çözdü ama hala tam olarak çalışmıyor.

Visual Fox Pro
Function InternetVarMi

LParameters tcSiteAdi As String
 
If Empty(m.tcSiteAdi)
    m.tcSiteAdi = "http://www.google.com"
EndIf
 
Declare integer InternetCheckConnection in wininet.dll ;
  string lpszUrl, integer dwFlags, integer dwReserved
 
Return (InternetCheckConnection(m.tcSiteAdi,1,0) != 0)
EndFunc
/o---------------------o\
     www.haser.com
\o---------------------o/

2

Re: İnternet bağlantısının kontrolünde sorun

Birde şu programı denermisin.

http://fox.wikis.com/wc.dll?Wiki~PingX~VFP

3

Re: İnternet bağlantısının kontrolünde sorun

Kodları nerden buldum hatırlamıyorum ama 2 farklı örnek işini görür umarım.
Kolay gelsin.


Visual Fox Pro
* Genel Çıkış IP si

 
UrlName="http://vbnet.mvps.org/resources/tools/getpublicip.shtml"
oHTTP=NEWOBJECT("winhttp.winhttprequest.5.1")
oHTTP.Open("GET",UrlName,.F.)
oHTTP.Send()
ohTTP.ResponseText
nFirstSingleQuote=AT("'",ohTTP.ResponseText)
nLengthToPull=AT("'",ohTTP.ResponseText,2)-nFirstSingleQuote-1
? SUBSTR(ohTTP.ResponseText,nFirstSingleQuote+1,nLengthToPull)
 
* Local IP
oWinSock = CreateObject("MSWinsock.Winsock")
?oWinSock.LocalIP
 
LOCAL IPSocket
crlf=chr(13)+chr(10)
&&local ip adresi
IPSocket = CreateObject("MSWinsock.Winsock")
 
if type('IPSocket')='O'
    IPAddress = IPSocket.LocalIP
    localhostname=IPSocket.localhostname
    remotehost=IPSocket.remotehost
    remotehostip=IPSocket.remotehostip
    MessageBox ("Local IP = " + IPAddress+crlf+"local host = "+localhostname;
    +crlf+"Remotehost = "+remotehost+crlf+"Remotehostip = "+remotehostip)
else
    MessageBox ("Winsock Yuklu Degil!")
ENDIF
 
 
* Başka örnek
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
 
CLEA
If WSAStartup(0x202,Repli(Chr(0),512))=0
  *? GetIP("network teki bir bilgisayar ismi")
  *? GetIP("localhost")
  ? GetIP(Alltrim(Strextract(Id(),"","#")))
  =WSACleanup()
Endif
 
Function GetIP(cServer)
  #Define HOSTENT_SIZE 16
  Local nStruct,nSize,cBuffer,nAddr,cIP
  nStruct=gethostbyname(cServer)
  If nStruct=0
    Return "0.0.0.0"
  Endif
  cBuffer=Repli(Chr(0),HOSTENT_SIZE)
  cIP=Repli(Chr(0),4)
  =CopyMemory(@cBuffer,nStruct,HOSTENT_SIZE)
  =CopyMemory(@cIP,buf2dword(Subs(cBuffer,13,4)),4)
  =CopyMemory(@cIP,buf2dword(cIP),4)
  Return inet_ntoa(buf2dword(cIP))
Endfunc
 
Function buf2dword(lcBuffer)
  Return Asc(Substr(lcBuffer,1,1))+Bitlshift(Asc(Subs(lcBuffer,2,1)),8)+;
    Bitlshift(Asc(Subs(lcBuffer,3,1)),16)+Bitlshift(Asc(Subs(lcBuffer,4,1)),24)
Endfunc
Uğur
-------------------------------------------------------------------------------------------------------------
Hayat bir bisiklete binmek gibidir. Pedalı çevirmeye devam ettiğiniz sürece düşmezsiniz. Claude Peppeer
Kusuru söylenmeyen adam, ayıbını hüner sanır.  Türk Atasözü

4

Re: İnternet bağlantısının kontrolünde sorun

Visual Fox Pro
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
 
  ?GetIP("network teki bir bilgisayar ismi")
 
  ** veya
 
  ?GetIP("localhost")
 
  ** veya
 
  ?GetIP(Alltrim(Strextract(Id(),"","#")))
 
  =WSACleanup()
Endif
 
**************************************************************************
Function GetIP(cServer)
  #Define HOSTENT_SIZE 16
  Local nStruct, nSize, cBuffer, nAddr, cIP
  nStruct = gethostbyname(cServer)
  If nStruct = 0
    Return '0.0.0.0'
  Endif
 
  cBuffer = Repli(Chr(0), HOSTENT_SIZE)
  cIP = Repli(Chr(0), 4)
 
  = CopyMemory(@cBuffer, nStruct, HOSTENT_SIZE)
  = CopyMemory(@cIP, buf2dword(Subs(cBuffer,13,4)),4)
  = CopyMemory(@cIP, buf2dword(cIP),4)
  Return inet_ntoa(buf2dword(cIP))
Endfunc
**************************************************************************
Function buf2dword(lcBuffer)
  Return Asc(Substr(lcBuffer, 1,1)) + ;
    Bitlshift(Asc(Subs(lcBuffer, 2,1)),8) +;
    Bitlshift(Asc(Subs(lcBuffer, 3,1)),16) +;
    Bitlshift(Asc(Subs(lcBuffer, 4,1)),24)
Endfunc
Uğur
-------------------------------------------------------------------------------------------------------------
Hayat bir bisiklete binmek gibidir. Pedalı çevirmeye devam ettiğiniz sürece düşmezsiniz. Claude Peppeer
Kusuru söylenmeyen adam, ayıbını hüner sanır.  Türk Atasözü