Seite 1 von 1

statisch oder dhcp

Verfasst: 04.09.2006 21:17
von pws32
Hallo,

weis einer wie man mit hilfe von PB(4.0) herhausfinden kann ob ein Computer eine statische IP hat, oder seine IP über DHCP bezieht?

Gruss Peter

Verfasst: 04.09.2006 21:21
von AND51
Wenn niemand etwas genaueres weiß, dann folgenden "Umweg":

1. RunProgram("ipconfig.exe", "/all >C:\DHCP.txt", "")
2. Datei C:\DCHP.txt auslesen und auswerten.

Verfasst: 05.09.2006 16:48
von stbi
Guck mal hier, da gibts ein Flag DHCPEnabled, das kannst Du auswerten.

Verfasst: 06.09.2006 08:42
von pws32
Hi,

habe im int. Forum noch einen Code entdeckt und etwas erweitert

Code: Alles auswählen

; 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