Konu: Çıkış İp'si
Arkadaşlar Hepinize Merhabalar
Visual Fox Pro komutları ile İnternet Çıkış İp 'mizi görmemiz mümkün mü acaba böyle bi işlem yapılabilir mi?
Giriş yapmadınız. Lütfen giriş yapın yada kayıt olun.
fox4um » Web Uygulamaları » Çıkış İp'si
Arkadaşlar Hepinize Merhabalar
Visual Fox Pro komutları ile İnternet Çıkış İp 'mizi görmemiz mümkün mü acaba böyle bi işlem yapılabilir mi?
Merhaba
Bu kod var.
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
Bu kodda routerin çıkış IP'sini verir. Ama bunu www.whatismyip.org adresinden okuyor.
Bu servis 60 sn. içinde 2 kez okumaya izin vermiyor galiba.
** router ıp adresini gösterir
*************************
clea
UrlName="http://www.whatismyip.org/"
cTempFile=ADDBS(GETENV("TEMP"))+SYS(3)+".htm"
LOCAL oHTTP as "winhttp.winhttprequest.5.1"
LOCAL cHTML
oHTTP=NEWOBJECT("winhttp.winhttprequest.5.1")
oHTTP.Open("GET",UrlName,.F.)
oHTTP.Send()
? ohTTP.ResponseText
biraz daha kisa yolu
oWinSock = CreateObject("MSWinsock.Winsock")
?oWinSock.LocalIP
Winsock kontrolu yaparakta ;
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
ben serverden dışarıya çıkış ip yi almak için aşağıdaki programı kullanıyorum
*FUNCTION GetInternetIP
DECLARE INTEGER URLDownloadToFile IN urlmon.dll;
INTEGER pCaller, STRING szURL,;
STRING szFileName, INTEGER dwReserved,;
INTEGER lpfnCB
LOCAL cRemoteURL, cLocalFile, nResult, cReturn
cRemoteURL = "http://vbnet.mvps.org/resources/tools/getpublicip.shtml"
cLocalFile = SYS(2023) + "\" + SYS(2015) + ".txt"
cReturn = ""
ThisForm.mesaj.Caption= "IP alınıyor"
nResult = URLDownloadToFile(0, cRemoteURL, cLocalFile, 0,0)
IF nResult = 0
*-- success, now lets load to string and parse results
LOCAL cIPFile
cIPFile = FILETOSTR(cLocalFile)
*-- should occur 2 times in the result, otherwise problem
IF OCCURS("'",cIPFile) = 2
LOCAL nFirstSingleQuote,nLengthToPull
nFirstSingleQuote = AT("'",cIPFile)
nLengthToPull = AT("'",cIPFile,2) - nFirstSingleQuote - 1
cReturn = SUBSTR(cIPFile,nFirstSingleQuote + 1,nLengthToPull)
* ? creturn
ENDIF
ENDIF
IF FILE(cLocalFile)
ERASE (cLocalFile)
ENDIF
RETU cReturn
Konukanın programıyla benimkini birleştirdim.
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)
Çok Teşekkürler Arkadaşlar Çok Sağolun.
fox4um » Web Uygulamaları » Çıkış İp'si