on 7/20/00 1:27 PM, Bob Feighner at [log in to unmask] wrote:
> I am trying to find a way to display the IP addresses of all that are
> currently
> logged on to our HP 3K.
Here is a small C program I wrote a few years ago based on CI script that
someone else did. The script was just to slow for my tastes. This also sorts
it by IP address and shows you the number of unique workstations.
-Lane
---------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
void strip( char *str )
{
int i;
i = strlen( str );
while( ( str[ i-1 ] <= ' ' ) && i > 0 )
i--;
str[ i ] = 0;
}
int compar( const char *str1, const char *str2 )
{
return( memcmp( str1+62, str2+62, 15 ) );
}
main()
{
FILE *nswork;
char temp[ 100 ];
char SessionNum[ 10 ];
char SessionName[ 30 ];
char WorkStationID[ 30 ];
#define NSmax 200
char NSlogins[ NSmax ][ 80 ];
int NScount;
int i;
int WorkStations;
char LastWorkStation[ 20 ];
system( "purge nswork,temp > $null" );
system( "build nswork; temp; rec=-80,,f,ascii" );
system( "listf ci.pub.sys,8 > nswork" );
nswork = fopen( "nswork", "r" );
if( nswork == NULL )
{
printf( "Unable to open NSwork\n" );
exit(1);
}
NScount = 0;
while( fgets( temp, 80, nswork ) != NULL )
{
if( memcmp( &temp[ 56 ], "REM :", 5 ) == 0 )
{
if( NScount >= NSmax )
{
printf( "Maximum # of sessions reached!\n" );
break;
}
memcpy( NSlogins[ NScount ], temp, 80 );
NScount++;
}
}
qsort( NSlogins, NScount, 80, compar );
printf( "\n" );
printf( "Session Logon Workstation/Machine\n" );
printf( "-------- --------------------------
------------------------------
-\n" );
WorkStations = 0;
strcpy( LastWorkStation, "********" );
for( i = 0; i < NScount; i++ )
{
memcpy( temp, NSlogins[ i ], 80 );
memcpy( SessionNum, temp, 8 );
SessionNum[ 8 ] = 0;
memcpy( SessionName, &temp[ 8 ], 26 );
SessionName[ 26 ] = 0;
memcpy( WorkStationID, &temp[ 62 ], 15 );
WorkStationID[ 15 ] = 0;
strip( WorkStationID );
if( strcmp( WorkStationID, LastWorkStation ) != 0 )
{
WorkStations++;
strcpy( LastWorkStation, WorkStationID );
}
else
{
sprintf( temp, "\x1b&dH%s\x1b&d@", WorkStationID );
strcpy( WorkStationID, temp );
}
printf( "%s %s %s\n", SessionNum, SessionName, WorkStationID );
}
printf( "\n" );
printf( "Total number of sessions = %d\n", NScount );
printf( "Total number of work stations = %d\n", WorkStations );
printf( "\n" );
}
|