1

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?

2

Re: Çıkış İp'si

Merhaba
Bu kod var.


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
 
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

3

Re: Çıkış İp'si

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.


Visual Fox Pro
** 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

4

Re: Çıkış İp'si

biraz daha kisa yolu

Visual Fox Pro
oWinSock = CreateObject("MSWinsock.Winsock")

?oWinSock.LocalIP

Winsock kontrolu yaparakta ;

Visual Fox Pro
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

5

Re: Çıkış İp'si

ben serverden dışarıya çıkış ip yi almak için aşağıdaki programı kullanıyorum

Visual Fox Pro
*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
VFP9 SP2

6

Re: Çıkış İp'si

Konukanın programıyla benimkini birleştirdim.

Visual Fox Pro
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)

7

Re: Çıkış İp'si

Çok Teşekkürler Arkadaşlar Çok Sağolun.