Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get local IP Address/Machine name with COBOL 2

Status
Not open for further replies.

dlong1969

Programmer
Jan 28, 2003
5
US
Hi,

I am attempting to find a way to get the local PC IP Address/Network Name using COBOL. I am running MF COBOL through an emulator on computers running WINNT through XP. The COBOL applications are running on SCO Openserver. I need to collect the local IP/Network name so I can fire off a VB executable on the machine that the COBOL app is running on. Any help would be appreciated.

Thanks

Don
 
Ask that question on the Unix/Windows forums. (without mentioning COBOL as it is not required)

As you mention an emulator I assume a terminal emulator.
If so look at commands "who", "finger" and "ps", but Unix forum will be better.

Once you determine which OS command is available to give you the information you just need to redirect it's output to a file and process that file as a normal "line sequential" or "sequential" file.




Regards

Frederico Fonseca
SysSoft Integrated Ltd
 
Don,

If you are not away at the Windows/Unix, etc... forums, here is a hint as to what is required to obtain the local PC IP Address(es)/Network Name.

1. You will need to access some basic Winsock API functions. For example, ws2_32.dll.

This (strictly untested, and not meaning to) VB example will get the PC hostname (in strHostName) and all the IPs for that PC:
Code:
Public Declare Function gethostname _
    Lib "ws2_32.dll" (ByVal host_name As String, _
                      ByVal namelen As Long) As Long

        Dim strHostName As String * 256
        Dim lngRetVal As Long
        lngRetVal = gethostname(strHostName, 256)
You will then need to sift thru the adress list of strHostName to retrieve all the IPs, like so:
Code:
Imports System.Net
Dim ipaddress
Dim i As Integer = 0
For each ipAddress in strHostName.AddressList
   i += 1
   thisIP(i) = ipaddress.ToString()
Next
Now, all you have to do is get your COBOL compiler to do something similar.[noevil]

Dimandja
 
"Now, all you have to do is get your COBOL compiler to do something similar."

No need to do that in COBOL because MF COBOL is able to call code written in VB or C(++).

Marcel
 
"No need to do that in COBOL because MF COBOL is able to call code written in VB or C(++)"

My understanding of Don's post is that he simply wants to obtain the IP addresses. So, why not call the plucky APIs? The alternative will be for Don to code yet another program in another language - a handful.

Dimandja
 
All -

I think Frederico and I read the question differently than some of you. Did we misunderstand?

I thought the COBOL code was running on SCO via terminal emulation. On the SCO box, the user needs the IP address of the PC running the terminal emulator. So the question, as I understand it, is how to do this in COBOL on the SCO box.

I don't know enough about UNIX/SCO to respond.

Regards.

Glenn
 
All -

Thank you for all of your responses. I came up with a workable solution to this problem. the solution turned out to be fairly simple...

To get the IP/Network Name for the machine you are running the terminal emulator on, I did the following

on SCO

do a SYSTEM call using 'who -x -m > temp.dat'. This will return the login information, including the PC name. After the command completes, parse the return to extract the PC Name. I can then use the PC name in an rsh command I am constructing to fire a VB application on the local machine.

for AIX

do the same thing, only the SYSTEM call would be 'who am i'

This solution returns the Network Name as opposed to the IP address, but rsh can use the network name as well, so it works fine.

Thanks people

Don
 
Hew!

Thanks Don for sharing the solution. Looks like we all went a bridge too far.

Dimandja
 
Yes, Frederico (I reread your post) you were right on the money!

Dimandja
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top