Welcome Serena Central users! CLICK HERE
The migration of the Serena Central community is currently underway. Be sure to read THIS MESSAGE to get your new login set up to access your account.
neidingd Honored Contributor.
Honored Contributor.
933 views

Ping with c$socket

Hello,

ist it possible to make a ping with the c$socket library?

 

Greetings
David

0 Likes
7 Replies
Micro Focus Expert
Micro Focus Expert

RE: Ping with c$socket

I believe C$SOCKET only provides TCP sockets. The TCP/IP ping protocol is actually implemented with ICMP, not TCP.

However, if you simply want to test whether a machine is responding, you can use the return status of a connection attempt as a heuristic. Try to connect a client socket to some port on the target. If that succeeds, simply close the client socket; you know the machine is responding. If it fails, get the error code. ECONNRESET usually indicates the target is available. ENETUNREACH, EHOSTUNREACH, ETIMEDOUT, etc generally indicate the target machine is not available, either because it's not up or due to network failure.
0 Likes
neidingd Honored Contributor.
Honored Contributor.

RE: Ping with c$socket

ok, thanks for the info. I see that with the ICMP but was not sure if there is a way with c$socket.

I also tried to get the System.Net.NetworkInformation.Ping Class with NetDefGen, but i don't fint that class there.
I will look for another way to get a ping solution with cobol.
0 Likes
Micro Focus Expert
Micro Focus Expert

RE: Ping with c$socket

Have you considered a call to c$system with "ping servername" and redirecting to a file which you can then parse for the ip address.
0 Likes
neidingd Honored Contributor.
Honored Contributor.

RE: Ping with c$socket

I want to realize a multi-ping and i don't think that c$system is a real solution for it.

I check at moment the ActiveX @WbemScripting to use from WMI the Win32_PingStatus Class.
But seems this is also not fast enough. But at moment the best Solution i see.

the icmp.dll is also not a real solution, cause Microsoft don't support it in all systems anymore.
0 Likes
neidingd Honored Contributor.
Honored Contributor.

RE: Ping with c$socket

ok, i decided to test the PingStatus Class from WMI. But i have some problems to translate this VB code to cobol.

           

VB:

objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")

objWMIService = objSWbemLocator.ConnectServer(source)

                                Dim resultset = objWMIService.Get("Win32_PingStatus.Address='" & target & "'")

                                If Not IsDBNull(resultset.StatusCode) Then

                                    If resultset.StatusCode = 0 Then

                                        responsePA = resultset.ProtocolAddress

                                        responseRT = resultset.ResponseTime

Cobol:

      ***********************************************************
       create-wmi-locator section.
           create @SWbemLocator of @WbemScripting
                  handle in wmi-locator.

           modify wmi-locator @ConnectServer(
                            by name strServer    "localhost"    | Change to make ping from Other computer
                            by name strNamespace "root\CIMV2"
      *                      by name strUser      " "          | if use other computer
      *                      by name strPassword  " "          | if use other computer
                            )
                  returning wmi-service.

       create-wmi-locator-ende.
           exit.
       create-wmi-locator-e.
      ***********************************************************
       create-wmi-ping section.
           initialize wmi-objpath.

           string "Win32_PingStatus.Address='"
                  "10.21.55.201"
                  "'"
                  delimited by size into wmi-objpath.

           modify wmi-service @Get(
                            by name strObjectPath wmi-objpath
                            )
                  returning wmi-object.

           stop "test".

           inquire wmi-object
             @Properties::@Item("StatusCode")::@Value      in p-status
             @Properties::@Item("ProtocolAddress")::@Value in p-pAddress
             @Properties::@Item("ResponseTime")::@Value    in p-rTime.


       create-wmi-ping-ende.
           exit.
       create-wmi-ping-e.
      ***********************************************************
       single-ping section.
           perform create-wmi-locator.
           perform create-wmi-ping.

           display message box p-status
                   newline     p-pAddress
                   newline     p-rTime.

           destroy wmi-object.
           destroy wmi-service.
           destroy wmi-locator.

       single-ping-ende.
           exit.
       single-ping-e.
      ***********************************************************

The Part i marked red, the problem occurs.

I create the Locator, connect to the wmi-service.

I call the ping class with the address to ping.

The problem i have is, how do i inquire the single values from the responce.

I get a System Exception with Member not found.


Has here anyone experience?
I am not sure if i need to inquire the properties... i try to follow with the ActiveX DEF Utility to get correct Property.

0 Likes
neidingd Honored Contributor.
Honored Contributor.

RE: Ping with c$socket

ok, i found it. In cobol it is a bit more complicated i think then in VB

      ***********************************************************
       create-wmi-locator section.
           create @SWbemLocator of @WbemScripting
                  handle in wmi-locator.

           modify wmi-locator @ConnectServer(
                            by name strServer    "localhost"    | Change to make ping from Other computer
                            by name strNamespace "root\CIMV2"
      *                      by name strUser      " "          | if use other computer
      *                      by name strPassword  " "          | if use other computer
                            )
                  returning wmi-service.

       create-wmi-locator-ende.
           exit.
       create-wmi-locator-e.
      ***********************************************************
       create-wmi-ping section.
           initialize wmi-objpath.
           initialize p-status.
           initialize p-statusT.
           initialize p-pAddress.
           initialize p-rAddress.
           initialize p-rTime.

      ***  Set Ping command
           string "Win32_PingStatus.Address='"
                  "10.21.51.253'"
                  ",ResolveAddressNames=True" | for inquire Hostname (slower)
                  delimited by size into wmi-objpath.

      ***  Get Ping
           modify wmi-service @Get(
                            by name strObjectPath wmi-objpath
                            )
                  returning wmi-object.

      ***  Inquire PropertySet
           inquire wmi-object  @Properties in wmi-propSet.

      ***  Get Status
           modify  wmi-propSet @Item(
                            by name strName "StatusCode"
                            )
                   returning wmi-prob.
           inquire wmi-prob    @Value in p-status.
           destroy wmi-prob.

           evaluate p-status
              when     0
                   move "Success"                          to p-statusT
              when 11001
                   move "Buffer Too Small"                 to p-statusT
              when 11002
                   move "Destination Net Unreachable"      to p-statusT
              when 11003
                   move "Destination Host Unreachable"     to p-statusT
              when 11004
                   move "Destination Protocol Unreachable" to p-statusT
              when 11005
                   move "Destination Port Unreachable"     to p-statusT
              when 11006
                   move "No Resources"                     to p-statusT
              when 11007
                   move "Bad Option"                       to p-statusT
              when 11008
                   move "Hardware Error"                   to p-statusT
              when 11009
                   move "Packet Too Big"                   to p-statusT
              when 11010
                   move "Request Timed Out"                to p-statusT
              when 11011
                   move "Bad Request"                      to p-statusT
              when 11012
                   move "Bad Route"                        to p-statusT
              when 11013
                   move "TimeToLive Expired Transit"       to p-statusT
              when 11014
                   move "TimeToLive Expired Reassembly"    to p-statusT
              when 11015
                   move "Parameter Problem"                to p-statusT
              when 11016
                   move "Source Quench"                    to p-statusT
              when 11017
                   move "Option Too Big"                   to p-statusT
              when 11018
                   move "Bad Destination"                  to p-statusT
              when 11032
                   move "Negotiating IPSEC"                to p-statusT
              when 11050
                   move "General Failure"                  to p-statusT
              when other
                   move "Unknow"                           to p-statusT
           end-evaluate.

           if p-status not = zeroes go to create-wmi-ping-ende.

      ***  Get ProtocolAddress
           modify  wmi-propSet @Item(
                            by name strName "ProtocolAddress"
                            )
                   returning wmi-prob.
           inquire wmi-prob    @Value in p-pAddress.
           destroy wmi-prob.

      ***  Get ProtocolAddressResolved
           modify  wmi-propSet @Item(
                            by name strName "ProtocolAddressResolved"
                            )
                   returning wmi-prob.
           inquire wmi-prob    @Value in p-rAddress.
           destroy wmi-prob.

      ***  Get ResponseTime
           modify  wmi-propSet @Item(
                            by name strName "ResponseTime"
                            )
                   returning wmi-prob.
           inquire wmi-prob    @Value in p-rTime.
           destroy wmi-prob.

       create-wmi-ping-ende.
           exit.
       create-wmi-ping-e.
      ***********************************************************
       single-ping section.
           perform create-wmi-locator.
           perform create-wmi-ping.

           display message box "Status Code: " p-status
                   newline     "Status Text: " p-statusT
                   newline     "Address: "     p-pAddress
                   newline     "RespAddress: " p-rAddress
                   newline     "RespTime:    " p-rTime.

           destroy wmi-propSet.
           destroy wmi-object.
           destroy wmi-service.
           destroy wmi-locator.

       single-ping-ende.
           exit.
       single-ping-e.
      ***********************************************************

 


 

donant
New Member.

RE: Ping with c$socket

I used C# to create a simple .Net module to ping an address.

Here my code:

C#

using log4net;
using log4net.Config;
using System;
using System.IO;
using System.Reflection;
using System.Net.NetworkInformation;

namespace WGPing.Client
{
public class WGClient
{

private ILog _log { get; set; }

public WGClient()
{

this.createLog();

}

//Return a bool true if I ping the address
public bool PingHost(String nameOrAddress)
{
bool pingable = false;
Ping pinger = new Ping();
try
{
if (nameOrAddress != "0.0.0.0")
{
PingReply reply = pinger.Send(nameOrAddress);
if (reply != null) pingable = reply.Status == IPStatus.Success;
}
}
catch (PingException x)
{
_log.Error("Errore PingHost " + x.Message);
}
return pingable;
}


}
}

Cobol:

...
77 WGPing-Returnpic9(01) comp-x.
...
modify WgPing-Handle,
"@PingHost"(w-address)
giving WGPing-return.
 
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.