Get Local IP address from NAV 2013 R2

navuser1navuser1 Member Posts: 1,329
edited 2017-04-11 in NAV Three Tier
Dear all,

How to get the IP Addresses of the (RTC) Client Machines who is accessing the NAV SERVER ?


Regards,
Navuser1
Now or Never

Answers

  • EvREvR Member Posts: 178
  • NavNabNavNab Member Posts: 181
    Hello,

    You can try this code

    ActiveSession.GET(SERVICEINSTANCEID, SESSIONID);
    IPAddresses:= IPAddresses.List;
    IPAddresses.AddRange(Dns.GetHostAddresses(ActiveSession."Client Computer Name"));
    FOR i := 0 TO IPAddresses.Count - 1 DO BEGIN
    MESSAGE('%1', IPAddresses.Item(i));
    END;

    Where variables:

    870745u1dw61.png


    P.S: the client machine may have more than one IP address.
  • NavNabNavNab Member Posts: 181
    I forgot to mention that you may need to adapt the code. It works for NAV 2016. I did not tested it for NAV 2013 R2
  • navuser1navuser1 Member Posts: 1,329
    edited 2017-04-12
    Few Local Machines are using RDP for accessing the NAV DB, I need to know their the Local IP address.

    Is it possible ?
    Now or Never
  • EvREvR Member Posts: 178
    Possible...well maybe technically. But you would have to get the client session (RDP session) to ask Windows (netstat or something more modern?) to give you the remote ip address. Sounds like adding a lot of error-prone complexity to me.
  • NavNabNavNab Member Posts: 181
    Few Local Machines are using RDP for accessing the NAV DB, I need to know their the Local IP address.

    Is it possible ?

    Hi navuser1,

    1- you should give feedback if the suggested solutions worked or not.
    2- it is not too difficult to say "thank you" to people who are trying to help you.
    3- you're asking a second question that is different from the first one.

    In another note, as suggested by EvR, you may use netstat and try to find the IP address through TCP port 3389 if default. Otherwise you should look for port value in registry key: [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp]

    Another suggestion is to use the "Remote Desktop Services API reference".
  • navuser1navuser1 Member Posts: 1,329
    Thank you for your help.
    Now or Never
  • tabrezajaz@hotmail.comtabrezajaz@hotmail.com Member Posts: 2
    edited 2017-09-21
    Hi, NavNab

    I am unable to create a variable of DotNet type for Dns.

    I didn't find Dns class there.
    Please help me......
  • NavNabNavNab Member Posts: 181
    Hello @tabrezajaz@hotmail.com

    3u94j25062cj.jpg

    And you can download the object "COD92600_Get Local IP.txt"

    P.S: delete ".jpg" to get the correct object extension.
  • omerfarukomerfaruk Member Posts: 16
    edited 2023-09-21
    Hi, @NavNab
    In order to get client's Ip address, these dotnet variables should be tagged as RunOnClient as Yes, right?

    Second Question: Is it possible to use this for web client? (business central on prem 14)
  • NavNabNavNab Member Posts: 181
    Hi @omerfaruk

    The topic is dated, but if memory serves, you should opt for RunOnClient ๐Ÿ˜…
    My memory of .NET specifics is fuzzy at the moment. RunOnClient likely won't function on a web client due to .NET restrictions.
    Could you try it out and report back? ๐Ÿ˜‰
  • omerfarukomerfaruk Member Posts: 16
    NavNab wrote: ยป
    Could you try it out and report back? ๐Ÿ˜‰

    Thanks for the response, I tried unfortunately it doesn't work on web client, it produces this error: ( got via debug)

    o3zldhw3n1w3.png
Sign In or Register to comment.