Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GetIpNetTable
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Title:
Miscellaneous
Thread ID:
00823885
Message ID:
00825259
Views:
19
>How I can get the list of IP of a local net?

This retrieves the addresses from the IPNetTable.
* Program: GetIpAddrs.prg
* Author: George Tasker
* Date: August 28, 2003 - 8:53 AM
* Purpose: Returns the IP addresses
* from an IPNetTable structure

LPARAMETERS ta_IPs

DECLARE INTEGER GetIpNetTable IN IPHlpAPI.DLL;
  STRING @lpIPNetTable, INTEGER @pdwSize,;
  SHORT bOrder
LOCAL liSize, lcNetTable, llorder, loConvert,;
  lnentries, lnoffset, lni
STORE 0 TO liSize, llorder
lcNetTable = SPACE(1)
* Get the size of the structure
= GetIpNetTable(@lcNetTable, @liSize, llorder)
lcNetTable = SPACE(liSize)
IF GetIpNetTable(@lcNetTable, @liSize, llorder) = 0 THEN 
  SET PROCEDURE TO Con_Int ADDITIVE 
  loConvert = CREATEOBJECT('ConvertInt')
  * Get the number of entries
  lnoffset = 4
  lnentries = loConvert.StringToInteger(LEFT(lcNetTable, lnoffset))
  IF lnentries > 0 THEN 
    DIMENSION ta_IPs[lnentries]
    lnoffset = lnoffset + 1
    * Iterate through the structure
    FOR lni = 1 TO lnentries
      * Calculate the position of 
      * the IP Address
      lnIPStart = lnoffset + 8 + loConvert.StringToInteger(SUBSTR(lcNetTable, lnoffset + 4, 4)) + 2
      * Get the IP Address
      ta_IPs[lni] = TRANSFORM(ASC(SUBSTR(lcNetTable, lnIPStart, 1))) + "." +;
        TRANSFORM(ASC(SUBSTR(lcNetTable, lnIPStart + 1, 1))) + "." +;
        TRANSFORM(ASC(SUBSTR(lcNetTable, lnIPStart + 2, 1))) + "." +;
        TRANSFORM(ASC(SUBSTR(lcNetTable, lnIPStart + 3, 1)))
      * Get the Start position of the next record
      lnOffset = lnoffset + 16 + loConvert.StringToInteger(SUBSTR(lcNetTable, lnoffset + 4, 4)) + 2
    NEXT 
  ENDIF 
ENDIF 
CLEAR DLLS GetIpNetTable
RETURN

DEFINE CLASS ConvertInt AS CUSTOM

  FUNCTION IntegerToString
    
    LPARAMETER pnInteger, pnbytes
    
    LOCAL lcresult, lnbytes, lnmask,;
      lninteger, lni, lnchar
    lcresult = ""
    IF PCOUNT() = 2
      lnbytes = pnbytes
    ELSE
      * Default to DWORD
      lnbytes = 4
    ENDIF
    lninteger = pnInteger
    lnmask = 255
    FOR lni = 1 TO lnbytes
      lnchar = BITAND(lninteger, lnmask)
      lcresult = lcresult + CHR(lnchar)
      lninteger = BITRSHIFT(lninteger, 8)
    NEXT
    RETURN lcresult
  ENDFUNC
  
  FUNCTION StringToInteger
    
    LPARAMETER pcstring, plsigned
    
    LOCAL lnresult, lnlast, lni, llsigned,;
      lnmsb, lnmax
    lnresult = 0
    lnlast = LEN(pcstring)
    * Return Signed Integer?
    IF PCOUNT() = 2
      llsigned = plsigned
    ELSE
      llsigned = .F.
    ENDIF
    FOR lni = 1 TO lnlast
      lnresult = lnresult + ASC(SUBSTR(pcstring, lni, 1)) * (256 ^ (lni - 1))
    NEXT
    IF llsigned
      lnmsb = (lnlast * 8) - 1
      IF BITTEST(lnresult, lnmsb)
        lnmax = (2 ^ (lnmsb + 1))
        lnresult = lnresult - lnmax
      ENDIF
    ENDIF
    RETURN lnresult
  ENDFUNC
ENDDEFINE

* To use
DIMENSION a_ips[1]
DO GetIpAddrs WITH a_ips
lnlast = ALEN(a_ips, 1)
FOR lni = 1 TO lnlast
  ? a_ips[lni]
NEXT
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform