Get IP Address

This forum is meant for questions and discussions about the X# language and tools
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Get IP Address

Post by OhioJoe »

In VO I used the following to get the computer's IP address:

Code: Select all

_DLL FUNCTION GetIPAddress(cHost AS STRING) AS STRING PASCAL:VO28INET.GetIPAddress
Which of course created the following error after conversion to XSharp

Code: Select all

Unable to load DLL 'VO28INET': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Does anyone know of an XSharp equivalent ? I figured I'd ask first before cutting and pasting someone else's C# code

Thank you
Joe Curran
Ohio USA
User avatar
wriedmann
Posts: 3755
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

Get IP Address

Post by wriedmann »

Hi Joe,
you can find an anwer here:
https://stackoverflow.com/questions/132 ... name-to-ip
But you could instead add the VOInternetClasses.DLL to your application and use that.
Wolfgang
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

Get IP Address

Post by Juraj »

Hi Joje,

in my X# app i use this:

LOCAL hostName:=System.Net.Dns.GetHostName() AS STRING
LOCAL cIP:= System.Net.Dns.GetHostByName(hostName).AddressList[1].ToString() AS STRING

Juraj
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Get IP Address

Post by FFF »

Hi Juray,
the second line provokes here: warning VN3030: GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202

I tried to use this, and it works ;-), only difference ist, for "ByName" i get an IP4, with "Entry" an IP 6 address back.
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Juraj
Posts: 161
Joined: Mon Jan 09, 2017 7:00 am

Get IP Address

Post by Juraj »

Hi Karl,

I used it in one of the first of my XSharp application. Despite the warning, the program worked OK, so I did not solve it

Juraj
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Get IP Address

Post by robert »

Karl,

> warning VN3030

Are you using Vulcan?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Get IP Address

Post by FFF »

Robert,
ups - yes, silly me hasn't noticed - this test app was really old ;)

Changed it to X#/VO, swapped references, added VOInternetClasses.dll, compiles fine, albeit with the corresponding XS0618 warning - and it fails at runtime, because it can't find the latter (V 2.6.0.0), even when it is copied into bin.
Why?
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
User avatar
OhioJoe
Posts: 131
Joined: Wed Nov 22, 2017 12:51 pm
Location: United States

Get IP Address

Post by OhioJoe »

The following function compiles without warnings.

Code: Select all

FUNCTION XGetIPAddress(  ) AS STRING STRICT 
	LOCAL cHostName := System.Net.Dns.gethostname() AS STRING
	LOCAL cIP       := System.Net.Dns.gethostbyname(cHostName).AddressList[1].ToString() AS STRING
	RETURN cIP    // returns  192.168 ....
Thanks, Juraj. And Wolfgang and Fabrice and Robert.

That AddressList member is an array, which means it could return several IP addresses. I tested it here and it returned only one. But perhaps a more complete solution would be to loop AddressList and potentially return several IPs.
Joe Curran
Ohio USA
User avatar
Chris
Posts: 4906
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Get IP Address

Post by Chris »

Hi Karl,
FFF wrote:Robert,
ups - yes, silly me hasn't noticed - this test app was really old ;)

Changed it to X#/VO, swapped references, added VOInternetClasses.dll, compiles fine, albeit with the corresponding XS0618 warning - and it fails at runtime, because it can't find the latter (V 2.6.0.0), even when it is copied into bin.
Why?
This dll depends on VOWin32APILibrary.dll and XSHarp.code.dll and XSharp.RT.dll, have you included those as well?

.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
FFF
Posts: 1580
Joined: Fri Sep 25, 2015 4:52 pm
Location: Germany

Get IP Address

Post by FFF »

Yes, i have. Even made a new X# runtime app, added VOSDK classes, Win32Api and VoInternet, copiles flawless, but fails, now with wrong format...
GetIP.PNG
GetIP.PNG (133.26 KiB) Viewed 924 times
GetIP2.PNG
GetIP2.PNG (18.3 KiB) Viewed 924 times
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Post Reply