It is currently Tue Mar 31, 2020 7:39 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Listing Adapters with their IPs
PostPosted: Tue Aug 26, 2003 8:03 am 
Offline
User
User

Joined: Tue Jul 29, 2003 9:16 am
Posts: 55
Location: Canada
Code updated for 5.20+

For those who wanted this (myself included) i converted a VB code from AllApi.Net to PB to list adapters with their respective IPs:

Code:
Declare GetAdaptersInfo()
Structure IP_ADDR_STRING
  Nxt.l
  IP.b[16]
  Mask.b[16]
  Context.l
EndStructure

Structure IP_ADAPTER_INFO
  Nxt.l
  ComboIndex.l
  AdapterName.b[260]
  Description.b[132]
  AddressLength.l
  Adr.b[8]
  Index.l
  Type.l
  DhcpEnabled.l
  CurrentIpAddress.l
  IpAddressList.IP_ADDR_STRING
  GatewayList.IP_ADDR_STRING
  DhcpServer.IP_ADDR_STRING
  HaveWins.w
  PrimaryWinsServer.IP_ADDR_STRING
  SecondaryWinsServer.IP_ADDR_STRING
  LeaseObtained.l
  LeaseExpires.l
EndStructure

Structure FIXED_INFO
  HostName.b[132]
  DomainName.b[132]
  CurrentDnsServer.l
  DnsServerList.IP_ADDR_STRING
  NodeType.l
  ScopeId.b[260]
  EnableRouting.l
  EnableProxy.l
  EnableDns.l
EndStructure

Structure IP_INFO
  AdapterName.s
  IP.s
  AdapterType.l
  AdapterTypeDesc.s
EndStructure

Global Dim Adapters.IP_INFO(10)

GetAdaptersInfo()
If Total=-1:MessageRequester("Error","An error occured accessing adapter info",0):End:EndIf
For gg=1 To Total
  Debug "Adapter: "+Adapters(gg)\AdapterName
  Debug "Type: "+Adapters(gg)\AdapterTypeDesc
  Debug "IP: "+Adapters(gg)\IP
  Debug Adapters(gg)\AdapterType
  Debug ""
Next

End


Procedure GetAdaptersInfo()
  Shared Total
 
  res=GetNetworkParams_(0,@FixedInfoSize.l)
  If res<>0
    If res<>#ERROR_BUFFER_OVERFLOW
      Total=-1:ProcedureReturn
      End
    EndIf
  EndIf
  Dim FixedInfoBuffer.b(FixedInfoSize-1)
  res = GetNetworkParams_(@FixedInfoBuffer(0), @FixedInfoSize)
  If res=0
    CopyMemory(@FixedInfoBuffer(0),@FixedInfo.FIXED_INFO,SizeOf(FIXED_INFO))
    Hostname$=PeekS(@FixedInfo\Hostname, -1, #PB_Ascii)
    DNSServer$=PeekS(@FixedInfo\DnsServerList\IP, -1, #PB_Ascii)
    pAddrStr = PeekL(@FixedInfo\DnsServerList\Nxt)
    Repeat
      CopyMemory(pAddrStr,@Buffer.IP_ADDR_STRING,SizeOf(IP_ADDR_STRING))
      pAddrStr =Buffer\Nxt
    Until pAddrStr=0
  EndIf
 
  AdapterInfoSize.l=0
  res=GetAdaptersInfo_(0, @AdapterInfoSize)
  If res<>0
    If res<>#ERROR_BUFFER_OVERFLOW
      Total=-1:ProcedureReturn
    EndIf
  EndIf
  Dim AdapterInfoBuffer.b(AdapterInfoSize - 1) ;OK
  res=GetAdaptersInfo_(@AdapterInfoBuffer(0), @AdapterInfoSize.l) ;OK
 
  CopyMemory(@AdapterInfoBuffer(0),@AdapterInfo.IP_ADAPTER_INFO,SizeOf(IP_ADAPTER_INFO))
  pAdapt=AdapterInfo\Nxt
 
  Repeat
    CopyMemory(@AdapterInfo,@Buffer2.IP_ADAPTER_INFO,SizeOf(IP_ADAPTER_INFO))
    Select Buffer2\Type
      Case 1:AdType$="Ethernet Adapter"
      Case 2:AdType$="Token Ring Adapter"
      Case 3:AdType$="FDDI Adapter"
      Case 4:AdType$="PPP Adapter"
      Case 5:AdType$="Loopback Adapter"
      Case 6:AdType$="Slip Adapter"
      Case 23:AdType$="PPPoE Adapter"
      Default:AdType$="Unknown Adapter"
    EndSelect
   
   
    pAddrStr=Buffer2\IpAddressList\Nxt
    Repeat
      CopyMemory(@Buffer2\IpAddressList,@Buffer,SizeOf(IP_ADDR_STRING))
      Total=Total+1
      Adapters(Total)\AdapterName=PeekS(@Buffer2\Description, -1, #PB_Ascii)
      Adapters(Total)\AdapterType=Buffer2\Type
      Adapters(Total)\IP=PeekS(@Buffer\IP, -1, #PB_Ascii)
      Adapters(Total)\AdapterTypeDesc=AdType$
      pAddrStr=Buffer\Nxt
      If pAddrStr<>0:CopyMemory(pAddrStr,@Buffer2\GatewayList,SizeOf(IP_ADDR_STRING)):EndIf
    Until pAddrStr=0
   
    pAdapt=Buffer2\Nxt
    If pAdapt<>0:CopyMemory(pAdapt,@AdapterInfo,SizeOf(IP_ADAPTER_INFO)):EndIf
   
  Until pAdapt=0
EndProcedure


Cheers!

_________________
AMD 1.8 - 512mb - ATI All-In-Wonder Radeon 9000 pro - W2k Pro
BASIC programmers never die, they just return without gosub.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 26, 2003 11:45 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5797
Location: Germany
Hmm, I get "Error at line 84 : Source memory pointer is 0."

Timo

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 26, 2003 3:11 pm 
Offline
User
User

Joined: Tue Jul 29, 2003 9:16 am
Posts: 55
Location: Canada
Replace line 82 with this:
Code:
pAddrStr.l=@FixedInfo\DnsServerList\Nxt


tell me if it works

_________________
AMD 1.8 - 512mb - ATI All-In-Wonder Radeon 9000 pro - W2k Pro
BASIC programmers never die, they just return without gosub.


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 26, 2003 3:19 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5797
Location: Germany
Yep, works fine now.

btw: moved to the Tricks'n' Tips section, because it looks like a good tip to me 8)

Timo

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 26, 2003 5:18 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Apr 29, 2003 9:18 pm
Posts: 1459
Location: North by Northwest
On Win2kSp3 both versions work nice.
@Freak which WIN version do you have :?:

_________________

I am to provide the public with beneficial shocks.
Alfred Hitshock


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 26, 2003 6:20 pm 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 5:21 pm
Posts: 5797
Location: Germany
also Win2kSp3 (... or did I install Sp4 yet?)

Timo

_________________
quidquid Latine dictum sit altum videtur


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Aug 26, 2003 11:59 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

Joined: Fri Apr 25, 2003 6:03 pm
Posts: 3000
Location: Lincoln, UK
Works fine with WinXP Home SP1 :D

_________________
--Kale

Image


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Wed Aug 27, 2003 12:30 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Mon Jun 02, 2003 1:42 am
Posts: 2010
Location: Ashland, KY
Works well on XP Pro SP1 too

_________________
-Mitchell
Check out kBilling for all your billing software needs!
http://www.k-billing.com
Code Signing / Authenticode Certificates (Get rid of those Unknown Publisher warnings!)
http://codesigning.ksoftware.net


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Aug 28, 2003 6:30 am 
Offline
User
User

Joined: Tue Jul 29, 2003 9:16 am
Posts: 55
Location: Canada
Thanks for the feedback, i wondered where the thread went lol

Cheers!

_________________
AMD 1.8 - 512mb - ATI All-In-Wonder Radeon 9000 pro - W2k Pro
BASIC programmers never die, they just return without gosub.


Top
 Profile  
Reply with quote  
 Post subject: Resolved. [I've fixed code]
PostPosted: Fri May 19, 2006 11:14 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Mar 21, 2006 12:31 am
Posts: 1773
Location: Canada
Is this normal that this code doesn’t retrieve systems secondary DNS server?


Top
 Profile  
Reply with quote  
 Post subject: Re: Listing Adapters with their IPs
PostPosted: Thu Jan 02, 2020 4:16 pm 
Offline
New User
New User

Joined: Fri Oct 14, 2005 8:18 pm
Posts: 3
Hi, I tried to run this code and following error occurs:

Quote:
Line 2: Structure already declared: IP_ADDR_STRING (in a resident file).


Could some one please explain me, what that means?

SIncerely


Top
 Profile  
Reply with quote  
 Post subject: Re: Listing Adapters with their IPs
PostPosted: Thu Jan 02, 2020 5:43 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Fri Apr 25, 2003 5:10 pm
Posts: 529
Location: Doubs - France
Zerosurf wrote:
Hi, I tried to run this code and following error occurs:

Quote:
Line 2: Structure already declared: IP_ADDR_STRING (in a resident file).


Could some one please explain me, what that means?

SIncerely



There is 720 structures predefined in PB inside resident file (.res) with the last PB version.
IP_ADDR_STRING is declared in a resident file (), so you can remove the declaration in PB code or set the structure as a comment like this
Code:
; Structure IP_ADDR_STRING
;   Nxt.l
;   IP.b[16]
;   Mask.b[16]
;   Context.l
; EndStructure


structure could not be declared multiple times.

_________________
A+
Denis


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: Demivec and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye