Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IP Address function

184 views
Skip to first unread message

Martin

unread,
Apr 26, 2013, 11:28:09 AM4/26/13
to
I am trying to find my PCs IP address from within VO, I found this in
our code and I am trying to test it.

My address is 192.168.2.232 this returns 16.243.24.0

The second debug through a converter gives me 232.2.168.192

Any ideas what is wrong please?

Thanks

Martin

FUNC GetIPAddress1(cHost AS STRING) AS STRING PASCAL
// Takes a address string and returns IP string
LOCAL cRet AS STRING
LOCAL pHostEnt as _WInHostEnt
LOCAL Tmp1 as DWORD // VO 2.8 PHIL
LOCAL Tmp2 as DWORD
LOCAL Tmp3 as _winin_addr
LOCAL Tmp4 as psz


IF SLen(cHost) > 0
pHostEnt := gethostbyname(String2Psz(cHost))

IF pHostEnt != null_ptr
// VO 2.8 PHIL - changed data types
Tmp1 := DWORD(pHostEnt.h_addr_list)
hit_key(str(tmp1))
Tmp2 := DWORD(ptr(_cast, Tmp1))
hit_key(str(tmp2))
Tmp3 := @Tmp2
Tmp4 := inet_ntoa(Tmp3)

cRet := Psz2String(Tmp4)
ENDIF
ENDIF

RETURN cRet

Massimo Bighelli

unread,
Apr 26, 2013, 12:07:43 PM4/26/13
to
Martin,

this is my code:

sHost := AllTrim(HostName())
SELF:oDCwIP:value := GetIPAddress(sHost)

Massimo
*Massimo Bighelli* ARCA Sistemi S.r.l.

dlzc

unread,
Apr 26, 2013, 3:12:02 PM4/26/13
to
Dear Martin:

On Friday, April 26, 2013 8:28:09 AM UTC-7, Martin wrote:
...
> I am trying to find my PCs IP address from within
> VO,

This is stored in the registry, if all else fails.

> I found this in our code and I am trying to test it.
>
> My address is 192.168.2.232 this returns 16.243.24.0
>
> The second debug through a converter gives me
> 232.2.168.192

Which is correct, except byte reversed. So it looks like an "endian" problem.

Your IP address is a 32-it integer, or 4 8-bit bytes, or 4 single byte characters.

I would:
- Shell execute "IPCONFIG /all >this.txt"
- parse the text file this.txt
... lots easier to dual-platform on Linux this way

David A. Smith

Willie Moore

unread,
Apr 26, 2013, 3:23:28 PM4/26/13
to
Martin,

I would go with the code that Massimo posted. If you want a sample, look at
the NBTStat sample. It will not only give you the IP address on your
computer but show you how you can send a packet over the network to query
another computer. It is the same as doing a NBTStat -a from and cmd prompt.

Regards,
Willie
Vulcan VIP

"Martin" wrote in message news:_1xet.160753$ui1....@fx02.fr7...

Jamal

unread,
Apr 29, 2013, 11:09:16 AM4/29/13
to

Martin

unread,
Apr 30, 2013, 10:15:29 AM4/30/13
to
Thanks all, I should have left the original programmers name in - he
broke it when converting from a sample.

It seems to work fine now thankyou

tested on XP and W7
0 new messages