static or dhcp

Just starting out? Need help? Post your questions and find answers here.
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

static or dhcp

Post by PWS32 »

Hi,
have you code in pb to tests the netconfiguration, is the ip static or with dhcp configures?
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It's in the output from ipconfig /all.
PWS32
User
User
Posts: 85
Joined: Sat May 10, 2003 1:02 pm
Location: Germany

Post by PWS32 »

Hi,
im have found this code here in this Forum and have the code a little bit extended

Code: Select all

; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphlp/iphlp/getadaptersinfo.asp
; with the help of IPHlpAPI.inc from the Powerbasic include-file for the structures
; Microsoft isn´t quite a help here :-)

DHCPServerEnabled.s

Structure IP_ADDR_STRING
  pNext.l
  IpAddress.b[16]
  IpMask.b[16]
  Context.l
EndStructure

Structure IP_ADAPTER_INFO
Next.l
ComboIndex.l
AdapterName.b[260] ; MAX_ADAPTER_NAME_LENGTH + 4
Description.b[132] ; MAX_ADAPTER_DESCRIPTION_LENGTH + 4
AdressLength.l
Address.b[8] ; MAX_ADAPTER_ADDRESS_LENGTH
Index.l
Type.l
DhcpEnabled.l
CurrentIpAddressPTR.l
IpAddressList.IP_ADDR_STRING
GatewayList.IP_ADDR_STRING
DhcpServer.IP_ADDR_STRING
HaveWins.l
PrimaryWinsServer.IP_ADDR_STRING
SecondaryWinsServer.IP_ADDR_STRING
LeaseObtained.l
LeaseExpires.l
EndStructure

length.l=0
Result=GetAdaptersInfo_(0,@length) ; Get the length for Buffer
If Result=#ERROR_BUFFER_OVERFLOW
  *Buffer=AllocateMemory(length)
  Result=GetAdaptersInfo_(*Buffer,@length)
  If Result=#ERROR_SUCCESS
    adapters=length/SizeOf(IP_ADAPTER_INFO)
    For x=0 To adapters-1
      Debug "AdapterNr : "+Str(x+1)
      tempipinfo.IP_ADAPTER_INFO
      For i=0 To SizeOf(IP_ADAPTER_INFO)-1
        byte.b=PeekB(*Buffer+(x*640)+i)
        PokeB(tempipinfo+i,byte)
      Next
      Debug "Adapter : "+PeekS(@tempipinfo\Description)
      Debug "IP-Adress : "+PeekS(@tempipinfo\IpAddressList+4)
      Debug "Gateway : "+PeekS(@tempipinfo\GatewayList+4)
     
      Debug "P-Wins : "+PeekS(@tempipinfo\PrimaryWinsServer+4)
      Debug "S-Wins : "+PeekS(@tempipinfo\SecondaryWinsServer+4)
      
      
      ;Debug "DHCP-Server : "+PeekS(@tempipinfo\DhcpServer+4)
      If PeekS(@tempipinfo\DhcpServer+4) = "255.255.255.255"
        Debug "STATIC IP Configuration"
       Else
        Debug "DHCP Server Adress : " +PeekS(@tempipinfo\DhcpServer+4)
      EndIf
      
      
      mac$=""
      For i=0 To 5
        byte.b=PeekB(@tempipinfo\Address+i)
        If byte>=0
          mac$+RSet(Hex(byte),2,"0")
        Else
          mac$+RSet(Hex(byte+256),2,"0")
        EndIf
        If i<5
          mac$+":"
        EndIf
      Next
      Debug "MAC-Address "+mac$
    Next
  Else
    Debug "Error : "+Str(Result)
  EndIf
EndIf 
Post Reply