Topic
  • 5 replies
  • Latest Post - ‏2012-04-02T18:16:33Z by JohnxLong
JohnxLong
JohnxLong
63 Posts

Pinned topic IP in CLLE

‏2012-03-05T09:01:14Z |
Is there a simple way of obtaining the IP number of the current system in CLLE

Thanks in advance

John
Updated on 2012-04-02T18:16:33Z at 2012-04-02T18:16:33Z by JohnxLong
  • scott_klement
    scott_klement
    263 Posts

    Re: IP in CLLE

    ‏2012-03-06T01:05:06Z  
    Can I assume you are looking for the IP address? A system will almost always have more than one IP address.

    Can you explain what you're planning to do with the IP address? That'll help me understand which one you're looking for, and maybe I can come up with a good way to give it to you.
  • JohnxLong
    JohnxLong
    63 Posts

    Re: IP in CLLE

    ‏2012-03-26T13:42:35Z  
    Can I assume you are looking for the IP address? A system will almost always have more than one IP address.

    Can you explain what you're planning to do with the IP address? That'll help me understand which one you're looking for, and maybe I can come up with a good way to give it to you.
    Hi Scott,

    I'm trying to programatically add a remote outq so i can print to an ascii printer attached via ethernet.

    The problem I have is that I have over 300 iseries, the printer will have a static ip number that is configured to be a predefined offset from the iseries IP number.
    i.e.
    If the iseries is 192.168.1.10 then the ip number of the printer will be 192.168.1.20
    If the iseris is 192.168.1.49, then the ip number of the printer will be 192.168.1.59

    to acheive this I obviously need to know the ip number of the iseries I'm running on, to further complicate things, its a batch program, which prevents me from using something like QUSRJOBI

    Any suggestions or help would be greatly appreciated.
  • JohnxLong
    JohnxLong
    63 Posts

    Re: IP in CLLE

    ‏2012-03-26T15:20:58Z  
    • JohnxLong
    • ‏2012-03-26T13:42:35Z
    Hi Scott,

    I'm trying to programatically add a remote outq so i can print to an ascii printer attached via ethernet.

    The problem I have is that I have over 300 iseries, the printer will have a static ip number that is configured to be a predefined offset from the iseries IP number.
    i.e.
    If the iseries is 192.168.1.10 then the ip number of the printer will be 192.168.1.20
    If the iseris is 192.168.1.49, then the ip number of the printer will be 192.168.1.59

    to acheive this I obviously need to know the ip number of the iseries I'm running on, to further complicate things, its a batch program, which prevents me from using something like QUSRJOBI

    Any suggestions or help would be greatly appreciated.
    p.s. I appreciate that there are multiple interfaces, I've checked and currently I have 3, I can eliminate 127.0.0.1 but that still leaves me two.

    I have several interactive jobs that are always running and are on a static IP.

    I'm thinking of trying to get the IP number of one of these devices, from this I can calculate the IP of the iseries.

    Is it possible to get the IP number of a specific job/device?

    What do you think?

    John
  • scott_klement
    scott_klement
    263 Posts

    Re: IP in CLLE

    ‏2012-04-02T17:35:10Z  
    • JohnxLong
    • ‏2012-03-26T15:20:58Z
    p.s. I appreciate that there are multiple interfaces, I've checked and currently I have 3, I can eliminate 127.0.0.1 but that still leaves me two.

    I have several interactive jobs that are always running and are on a static IP.

    I'm thinking of trying to get the IP number of one of these devices, from this I can calculate the IP of the iseries.

    Is it possible to get the IP number of a specific job/device?

    What do you think?

    John
    The QDCRDEVD API can give you the IP address of an interactive (Telnet) job. It can tell you either the IP address of the PC that's connected via Telnet, or it can tell you the IP address of the IBM i TCP/IP interface that the telnet session has connected to.

    I don't know if that helps, since it sounds like you have multiple interfaces.

    another approach is to use the gethostname() API to get the "canonical" hostname of the system, and then do a DNS lookup on that hostname to get an IP address. That assumes that the canonical hostname will refer to the IP address you're looking for (I don't know if that works in your scenario?)

    Personally, I think hard-coding an IP address in a device description or outq is a really bad idea. I use domain names exclusively. The idea is that if a change in IP address (often necessitated by a change in network layout) is needed, you only have to change it in two places: The interface configuration (of your printer) and DNS. Once changed, everything automatically sees the new address.
  • JohnxLong
    JohnxLong
    63 Posts

    Re: IP in CLLE

    ‏2012-04-02T18:16:33Z  
    The QDCRDEVD API can give you the IP address of an interactive (Telnet) job. It can tell you either the IP address of the PC that's connected via Telnet, or it can tell you the IP address of the IBM i TCP/IP interface that the telnet session has connected to.

    I don't know if that helps, since it sounds like you have multiple interfaces.

    another approach is to use the gethostname() API to get the "canonical" hostname of the system, and then do a DNS lookup on that hostname to get an IP address. That assumes that the canonical hostname will refer to the IP address you're looking for (I don't know if that works in your scenario?)

    Personally, I think hard-coding an IP address in a device description or outq is a really bad idea. I use domain names exclusively. The idea is that if a change in IP address (often necessitated by a change in network layout) is needed, you only have to change it in two places: The interface configuration (of your printer) and DNS. Once changed, everything automatically sees the new address.
    Hi Scott,

    Thanks for taking the time to reply, I opted to grab the device description from an active job and then use QDCRDEVD to get the IP of the host, clumsy but functional and gets me exactly what I need.

    I tried the gothostname approach, but it returned blanks, and using gethostbyname on "localhost" simply returned the expected 127.0.0.1.

    I agree with hardcoding anything, normally I avoid it like the plague, but this is historic and with over 300 systems in my estate, its not practical to change at this point in time.

    Thanks again for the help

    John