How do i get list of IP Address of computers in a network ?

Post Reply
User avatar
shahir.fivewin
Posts: 14
Joined: Thu Jun 26, 2014 10:18 am

How do i get list of IP Address of computers in a network ?

Post by shahir.fivewin »

How do i get list of IP Address of computers in a network ?
User avatar
cnavarro
Posts: 5792
Joined: Wed Feb 15, 2012 8:25 pm
Location: España

Re: How do i get list of IP Address of computers in a network ?

Post by cnavarro »

C. Navarro
Hay dos tipos de personas: las que te hacen perder el tiempo y las que te hacen perder la noción del tiempo
Si alguien te dice que algo no se puede hacer, recuerda que esta hablando de sus limitaciones, no de las tuyas.
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: How do i get list of IP Address of computers in a network ?

Post by FranciscoA »

Look at this sample's code. Maybe some help.

Code: Select all

//--------------------------//
Function GetIPs(cEquipo)
local cIP

DEFAULT cEquipo := "LOCAL"

   WsaStartUp() 

 if upper(cEquipo) == "LOCAL"
   cIP := GetHostByName( GetHostName() )   //IP equipo local
 elseif upper(cEquipo) == "SERVIDOR"
   cIP := GetHostByName(cNombServ)    //IP equipo en red segun nombre dado
 endif

   //GetHostByAddress("192.168.0.14")    // NOMBRE del equipo en RED segun IP dada
   //NetName(.f.)    // NOMBRE del equipo en RED
   //NetName(.t.)    // NOMBRE del usuario del equipo en RED

   WsaCleanUp() 

Return cIP
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: How do i get list of IP Address of computers in a network ?

Post by Rick Lipkin »

Francisco

I have enjoyed looking at your Ldap queries .. Hopefully soon, I will be changing jobs, and I would like to be able to query 'Active Directory' for many of the attributes you have shown in your examples.

I would be most grateful, if you would not mind sharing ( or I would be willing to pay ) for your library of LDAP code.

Let me know...

Thanks
Rick Lipkin
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: How do i get list of IP Address of computers in a network ?

Post by FranciscoA »

Rick.
I took the information, from here:

http://www.activexperts.com/network-mon ... ection.htm

I hope you find it useful.

Sample:

Code: Select all

//--------------------------------------//
Function FapSoftScan(oVent)
local oDlg, oBrw, oCbx, oBt1,oBt2
local nWidthRes := GetSysMetrics(SM_CXSCREEN)  
local nHeightRes := GetSysMetrics(SM_CYSCREEN)
local aInfo:={}, aTitCols:={}, aWMIscan, bMonitoring, bEndProcess, bBt1
local cVar, nPos:=1, n
local aOptions := {"01  Grupo de Programas      (Win32 Logical Program Group)  ",;
                   "02  Sistema del Ordenador   (Win32 Computer Systen)        ",;
                   "03  Recursos Compartidos    (Win32 Share)                  ",;
                   "04  Servicios               (Win32 Service)                ",;
                   "05  Cliente de Red          (Win32 Network Client)         ",;
                   "06  Conexiones              (Win32 Network Connection)     ",;
                   "07  Perfil de Red           (Win32 Network Login Profile)  ",;
                   "08  Procesos                (Win32 Process)                ",;
                   "09  Discos                  (Win32 Logical Disks)          ",;
                   "10  Impresoras              (Win32 Printer)                " }

local oLoc, oWMI

TRY
   oLoc:= CreateObject( "wbemScripting.SwbemLocator" )
CATCH 
   MsgStop("No se pudo crear objeto 'wbemScripting.SwbemLocator'","Alto")
   Quit
END

TRY
   oWMI := oLoc:ConnectServer()
CATCH 
   MsgStop("No se pudo conectar a WMI","Alto")
   Quit
END

bMonitoring := {|| aWMIscan:=FapMonitoring(nPos,oWMI,18) ,;
                   aInfo:=aWMIscan[1], aTitCols:=aWMIscan[2],;
                   oBrw:SetArray(aInfo,.t.,1,.t.),;
                   oBrw:cHeaders := aTitCols, ;
                   oBrw:nHeadStrAligns := AL_CENTER, ;   //    oBrw:nWidths := 160 ,;
                   AEval(oBrw:aCols,{|o,n,oCol|  if(ValType(o:Value) =="N", o:nWidth := Max( 40, oBrw:aCols[n]:HeaderWidth() ), o:nWidth:=160) }),;
                   oBrw:nColSel := 1, oBrw:Refresh(.t.),;
                   oBrw:SetFocus(), CelRowTooltip(oBrw) }


bBt1 := {|| if(nPos == 8,oBt1:Show(),oBt1:Hide()) }

bEndProcess := {|cProc, nRec, nHnd| nRec:=oBrw:nArrayAt,;
                 if( nPos == 8,;
                   ( cProc := oBrw:aArrayData[oBrw:nArrayAt,oBrw:Name:nPos],;
                     nHnd  := oBrw:aArrayData[oBrw:nArrayAt,oBrw:ProcessID:nPos],;
                     FapEndProc(cProc,oWMI,nHnd),;
                     Eval(bMonitoring),;
                     oBrw:nArrayAt:=nRec-1,oBrw:Refresh(), oBrw:SetFocus() ),) }


DEFINE DIALOG oDlg SIZE oVent:nWidth, oVent:nHeight TITLE "FapSoftScan" TRANSPARENT

cVar := aOptions[1]

@ oDlg:nTop+10,8 COMBOBOX oCBx VAR cVar OF oDlg PIXEL;
                 ITEMS aOptions ;
                 SIZE 140,16 ;
                 ON CHANGE ( nPos := oCbx:nAt(), Eval(bMonitoring), Eval(bBt1) )

@1,1 XBROWSE oBrw OF oDlg ; 
     ARRAY {} CELL LINES FOOTERS AUTOSORT

     FapBrwSetup(oBrw)

     oBrw:CreateFromCode()

     Eval(bMonitoring)


 @ oDlg:nTop+245,8 BUTTONBMP oBt1 PROMPT "Finalizar Proceso" OF oDlg ;
                    SIZE 60, 12  PIXEL ;
                    BITMAP "BORRAR16x16" TEXTRIGHT ;
                    ACTION EVal(bEndProcess)

 @ oDlg:nTop+245,380 BUTTONBMP oBt2 PROMPT "Salir/Cancelar" OF oDlg ;
                    SIZE 60, 12  PIXEL ;
                    BITMAP "SALIR16x16" TEXTRIGHT ;
                    ACTION oDlg:End()
 
 ACTIVATE DIALOG oDlg CENTERED ;
   ON INIT ( oBrw:nHeight:=oDlg:nHeight-118, oBrw:nWidth:=oDlg:nWidth-34, oBrw:nTop:=oDlg:nTop+50 ,;
             oBt1:Hide(), oBrw:SetFocus() )

Return nil


//------------------------
Function FapBrwSetup(oBrw)
local nFONDO1 := RGB(215, 215, 215)
local nFONDO2 := RGB(235, 235, 235)
local nAZUL   := RGB( 0, 0, 128)

   WITH OBJECT oBrw
      :l2007            := .f.
      :nRecSelColor     :=  nFONDO1
      :nStyle           := nAnd( :nStyle, nNot( WS_BORDER ) )
      :nMarqueeStyle    := MARQSTYLE_HIGHLROW   //ilumina toda la linea
      :bClrHeader       := {|| { nAZUL, nFONDO1, } } 
      :bClrFooter       := :bClrHeader         // Colores texto de footers
      :bClrStd          := {|| IF( oBrw:nArrayAt() % 2 == 0, {nAZUL, nFONDO1}, {nAZUL, nFONDO2} ) }  
      :bClrSel          := {|| { nAZUL, CLR_WHITE } }  // para barra de linea selecc cuando el control no tiene el foco
      :bClrSelFocus     := { || { CLR_WHITE, nAZUL } }     // para barra de linea selecc cuando el control tiene el foco
      :lKinetic         := .f.
      :lContrastClr     := .f.  //para que no cambie color de texto automaticamente segun intensidad del fondo
      :nRowHeight       := 20 
      :nHeaderHeight    := 34
      :nColDividerStyle := LINESTYLE_LIGHTGRAY
      :nRowDividerStyle := LINESTYLE_LIGHTGRAY
   END

Return nil


//-------------------------------------------------------------
Function FapMonitoring(nOption,oWMI)
local oPC, oQry
local aInfo:={}, aTitCols, n,nLen

if nOption == 1
   oQry := oWMI:ExecQuery( "Select * FROM Win32_LogicalProgramGroup" )
   aTitCols:= {"Caption","Description","GroupName","Name","UserName","InstallDate","Status"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:GroupName, oPC:Name, oPc:UserName, oPc:InstallDate, oPc:Status} )
   next

elseif nOption == 2
   oQry := oWMI:ExecQuery( "Select * FROM Win32_ComputerSystem" )
   aTitCols:= {"Caption","Description","Domain","Model","Name","Processors","Status","System Type","User Name"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:Domain, oPC:Model, oPC:Name, oPc:NumberOfProcessors, oPc:Status, oPC:SystemType, oPC:UserName} )
   next   

elseif nOption == 3
   oQry := oWMI:ExecQuery( "Select * FROM Win32_Share" )
   aTitCols:= {"Caption","Description","Name","Path","Status","Type"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:Name, oPc:Path, oPc:Status, oPC:Type} )
   next   

elseif nOption == 4
   oQry := oWMI:ExecQuery( "Select * FROM Win32_Service" )
   aTitCols:= {"Caption","Description","DisplayName","Name","PathName","State","Status","SystemName"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:DisplayName, oPc:Name, oPC:PathName, oPc:State, oPc:Status, oPC:SystemName} )
   next
   
elseif nOption == 5
   oQry := oWMI:ExecQuery( "Select * FROM Win32_NetworkClient" )
   aTitCols:= {"Caption","Description","Name","Status","Manufacturer"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:Name, oPC:Status, oPC:Manufacturer} )
   next

elseif nOption == 6
   oQry := oWMI:ExecQuery( "Select * FROM Win32_NetworkConnection" )
   aTitCols:= {"Caption","Comment","Description","LocalName","Name","Persistent","RemoteName","RemotePath","Status","UserName","ConnectionState","ConnectionType"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Comment, oPC:Description, oPC:LocalName, oPC:Name, oPC:Persistent, oPc:RemoteName, oPc:RemotePath, oPC:Status, oPc:UserName, oPC:ConnectionState, oPC:ConnectionType} )
   next

elseif nOption == 7
   oQry := oWMI:ExecQuery( "Select * FROM Win32_NetworkLoginProfile" )
   aTitCols:= {"Caption","Comment","Description","FullName","HomeDirectory","HomeDirectoryDrive","Name","PasswordAge","Profile","ScriptPath","UserId","UserType","Workstations"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Comment, oPC:Description, oPC:FullName, oPC:HomeDirectory, oPC:HomeDirectoryDrive, oPc:Name, oPC:PasswordAge, oPc:Profile, oPc:ScriptPath, oPC:UserId, oPc:UserType, oPC:Workstations} )
   next

elseif nOption == 8
   oQry := oWMI:ExecQuery( "Select * FROM Win32_Process" )
   aTitCols:= {"Caption","Description","ExecutablePath","ExecutionState","Handle","HandleCount","Name","ProcessId","SessionId","Status"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:ExecutablePath, oPC:ExecutionState, oPC:Handle, oPC:HandleCount, oPc:Name, oPC:ProcessId, oPc:SessionId, oPc:Status} )
   next

elseif nOption == 9 
   oQry := oWMI:ExecQuery( "Select * FROM Win32_LogicalDisk" )
   aTitCols:= {"Caption","Description","DeviceID","DriveType","FileSystem","FreeSpace","InstallDate","MediaType","Name","Size","Status","SystemName","VolumeName","VolumeSerialNumber","ProviderName"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Caption, oPC:Description, oPC:DeviceID, oPC:DriveType, oPC:FileSystem, oPC:FreeSpace, oPc:InstallDate, oPC:MediaType, oPc:Name, oPc:Size, oPC:Status, oPC:SystemName, oPC:VolumeName, oPC:VolumeSerialNumber, oPC:ProviderName} )
   next

elseif nOption == 10
   oQry := oWMI:ExecQuery( "Select * FROM Win32_Printer" )
   aTitCols:= {"Name","DeviceID","ShareName","SystemName","PrinterState","PrinterStatus","Status"}
   for each oPC in oQry
      aadd(aInfo, {oPC:Name, oPC:DeviceID, oPC:ShareName, oPC:SystemName, oPc:PrinterState, oPc:PrinterStatus,oPC:Status} )
   next
endif

   //Agregar columna para numerar consecutivo
   Aadd(aTitCols,nil)
   AIns(aTitCols,1)
   aTitCols[1]:="No. "
   For n := 1 to len(aInfo)
      Aadd(aInfo[n],nil)
      AIns(aInfo[n],1)
      aInfo[n,1] := n
   Next

RETURN {aInfo,aTitCols}

//-----------------------------------//
FUNCTION FapEndProc(cProceso,oWMI,nHnd)
Local oQry, oProc

If MsgNoYes("Proceso: "+cProceso+CRLF+;
            "Esta seguro(a) de finalizar este proceso?","Finalizar Proceso")
   
   oQry := oWMI:ExecQuery( "SELECT * FROM Win32_Process WHERE Name = '"+cProceso+"'" )

   FOR EACH oProc IN oQry
      If UPPER(oProc:Name) == UPPER(cProceso) .and. oProc:ProcessID == nHnd
         oProc:Terminate()
      Endif
   NEXT

Endif
RETURN nil
 
Best regards.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: How do i get list of IP Address of computers in a network ?

Post by FranciscoA »

Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: How do i get list of IP Address of computers in a network ?

Post by FranciscoA »

Sorry, I forgot this function.

Code: Select all

//-------------------------//Ver contenido de celda-linea seleccionada en un tooltip
Function CelRowTooltip(oBrw)
local n     //Muestra contenido de la celda-linea seleccionada en un tooltip
     For n := 1 to len(oBrw:aCols)
        oBrw:aCols[n]:bToolTip := {|oBrw,nRow,nCol,nKeyFlas| ;
        IF(oBrw:MouseRowPos(nRow)==oBrw:nRowSel ,;
        if(!empty(oBrw:aCols[oBrw:MouseColPos(nCol)]:bStrData),;
        oBrw:aCols[oBrw:MouseColPos(nCol)]:bStrData,nil),) }
     Next
Return nil
 
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
User avatar
Rick Lipkin
Posts: 2397
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: How do i get list of IP Address of computers in a network ?

Post by Rick Lipkin »

Francisco

Thank you for your examples .. I did bookmark the link .. 'good stuff' 8) I appreciate your generosity!

Rick Lipkin
User avatar
FranciscoA
Posts: 1964
Joined: Fri Jul 18, 2008 1:24 am
Location: Chinandega, Nicaragua, C.A.

Re: How do i get list of IP Address of computers in a network ?

Post by FranciscoA »

Rick.
Thank you for your words.
Francisco J. Alegría P.
Chinandega, Nicaragua.

Fwxh1204-MySql-TMySql
Post Reply