Page 1 of 2
Posted: Sun May 12, 2002 10:28 am
by BackupUser
Restored from previous forum. Originally posted by jreimers.
Hello PB profs,
any idea about figuring out my own IP-address?
I´ve tried with API Call GetAdaptersInfo_, parameters seems to be correct
(I get description: NDIS 5.0 driver, Adaptername: {xyz...} from reg and the correct MAC).
IP-address is always empty, the link IP_ADAPTER_INFO\next is always NULL.
I´ve tried it also in VB 5.0 with the example in API-Guide vrom KPD (which I also used translated in PB), results are the same!
Of course, I have a NIC and IP installed, OS = W2K prof SP2
Posted: Sun May 12, 2002 12:19 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.
Hello PB profs,
any idea about figuring out my own IP-address?
I´ve tried with API Call GetAdaptersInfo_, parameters seems to be correct
(I get description: NDIS 5.0 driver, Adaptername: {xyz...} from reg and the correct MAC).
IP-address is always empty, the link IP_ADAPTER_INFO\next is always NULL.
I´ve tried it also in VB 5.0 with the example in API-Guide vrom KPD (which I also used translated in PB), results are the same!
Of course, I have a NIC and IP installed, OS = W2K prof SP2
Some time ago I posted a little codesnip that collects all IPs of your local system. Its very easy.
Code: Select all
; Convert Asigned Word to normal Byte
Procedure.l calc(va.b)
If va.b0
ipb1.b=PeekB(ipadr.l)
ip1.l=calc(ipb1.b)
ipb2.b=PeekB(ipadr.l+1)
ip2.l=calc(ipb2.b)
ipb3.b=PeekB(ipadr.l+2)
ip3.l=calc(ipb3.b)
ipb4.b=PeekB(ipadr.l+3)
ip4.l=calc(ipb4.b)
localips$(ip)=Str(ip1.l)+"."+Str(ip2.l)+"."+Str(ip3.l)+"."+Str(ip4.l)
st$+localips$(ip)+Chr(10):ip+1:offset.l+4
EndIf
Until h_addr_list=0
ProcedureReturn ip
EndProcedure
After calling the procedure, all available IPs should written into the array localips()
Hope it helps.
Mike
Tranquilizer/ Secretly!
Registred PureBasic User
Posted: Sun May 12, 2002 1:23 pm
by BackupUser
Restored from previous forum. Originally posted by PB.
> any idea about figuring out my own IP-address?
I haven't tried this myself, but v3.10 has an IPAddressGadget() which probably
does what you want...
PB - Registered PureBasic Coder
Posted: Sun May 12, 2002 3:55 pm
by BackupUser
Restored from previous forum. Originally posted by jreimers.
> any idea about figuring out my own IP-address?
I haven't tried this myself, but v3.10 has an IPAddressGadget() which probably
does what you want...
PB - Registered PureBasic Coder
thanks to PB, but it doesn´t, IPAddressGadget() offers only filling in theIP
jreimers
Posted: Sun May 12, 2002 4:02 pm
by BackupUser
Restored from previous forum. Originally posted by jreimers.
Thanks to tranquil,
this seems to make sense, but because Your code only returns empty strings (I think because winsock isn´t initialized and there are no error traps).
Do You have annother code snippet including the winsock initialisation?
Would be nice!
Posted: Sun May 12, 2002 8:24 pm
by BackupUser
Restored from previous forum. Originally posted by fred.
Just add 'InitNetwork()' and it should work..
Fred - AlphaSND
Posted: Mon May 13, 2002 1:09 pm
by BackupUser
Restored from previous forum. Originally posted by jreimers.
Just add 'InitNetwork()' and it should work..
Fred - AlphaSND
You´re right!
Nevertheless I Wonder, why GetAdaptersInfo_ doesn´t work
jreimers
Posted: Thu Aug 15, 2002 6:58 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.
Just add 'InitNetwork()' and it should work..
Fred - AlphaSND
I do it and only return void strings.
Im on XP with 2 lan cards and internet, i dont know if this makes not work.
Posted: Thu Aug 15, 2002 9:14 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.
I'm now using Windows 2000 2 LAN Cards, ISDN Card and Internet.
I get all IPs of my local system with the above procedure correctly. Hm...
Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
Posted: Thu Aug 15, 2002 10:02 pm
by BackupUser
Restored from previous forum. Originally posted by ricardo.
I'm now using Windows 2000 2 LAN Cards, ISDN Card and Internet.
I get all IPs of my local system with the above procedure correctly. Hm...
But what can i doing wrong?
I add the InitNetwork()line at the begginig and the rest of the code as is and nothing, only void strings.
If i check what is happenning i saw that:
adr.l=gethostbyname_(*buffer) get a value
h_name.l=PeekL(adr.l) ;Point to host name get a value
ip=0:offset.l=0
Repeat
h_addr_list=PeekL(adr.l+16+offset.l) ; List of Addresses (IPs) void
and the ofcourse it skip this part (since h_addr_list = 0)
If h_addr_list0
...
thats why im getting no results.
Posted: Fri Aug 16, 2002 6:13 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.
Add some
error checking and try again.
Maybe InitNetwork() fails for you...
Code: Select all
Dim localips$(10)
Procedure.l calc(va.b)
; Convert Asigned Word to normal Byte
If va.b0
ipb1.b=PeekB(ipadr.l)
ip1.l=calc(ipb1.b)
ipb2.b=PeekB(ipadr.l+1)
ip2.l=calc(ipb2.b)
ipb3.b=PeekB(ipadr.l+2)
ip3.l=calc(ipb3.b)
ipb4.b=PeekB(ipadr.l+3)
ip4.l=calc(ipb4.b)
localips$(ip)=Str(ip1.l)+"."+Str(ip2.l)+"."+Str(ip3.l)+"."+Str(ip4.l)
st$+localips$(ip)+Chr(10):ip+1:offset.l+4
EndIf
Until h_addr_list=0
ProcedureReturn ip
EndProcedure
If InitNetwork()
IPcount = getIPs()
If IPcount
A$ = "IP´s available: "+Str(IPcount)+Chr(13)+Chr(13)
For a = 0 To IPcount - 1
A$ + "IP " + Str(a) + " : " + localips$(a) + Chr(13)
Next a
Else
A$ = "No IP´s found"
EndIf
MessageRequester("IP INFO",A$,0)
Else
MessageRequester("ERROR","Cant initialize Network!",0)
EndIf
cya,
...Danilo
(registered PureBasic user)
Posted: Fri Aug 16, 2002 6:59 am
by BackupUser
Restored from previous forum. Originally posted by Danilo.
@
Tranquil:
The line " a=gethostname_(*buffer,2048) " in your
procedure getIPs() is useless (not needed).
Same with " st$+localIPs$(ip)+Chr(10) " - dead code.
Your procedure calc() isnt needed here.
We have StrU() for that in PureBasic.
So the 8 variables ip1, ip2, ip3, ip4, ipb1, ipb2, ipb3, ipb4
are not needed anymore.
Maybe you want to change it, so you can get the
Hostname in localIPs$(0) and all IPs after that:
Code: Select all
IPmax = 10
Dim localips$(IPmax)
Procedure.l getIPs()
Shared localIPs$,IPmax
*buffer = GlobalAlloc_(#GMEM_FIXED | #GMEM_ZEROINIT, 65536)
Dim localIPs$(IPmax) ; Remove all existent IPs from list ( REDIM = Clear )
a=gethostname_(*buffer,2048)
localIPs$(0) = UCase(PeekS(*buffer))
adr.l=gethostbyname_(*buffer)
h_name.l=PeekL(adr.l) ;Point to host name
ip=0:offset.l=0
Repeat
h_addr_list=PeekL(adr.l+16+offset.l) ; List of Addresses (IPs)
ipadr.l=h_addr_list
If h_addr_list0
localIPs$(ip+1)=StrU(PeekB(ipadr.l),0)+"."+StrU(PeekB(ipadr.l+1),0)+"."+StrU(PeekB(ipadr.l+2),0)+"."+StrU(PeekB(ipadr.l+3),0)
;st$+localIPs$(ip)+Chr(10)
ip+1:offset.l+4
EndIf
Until h_addr_list=0
ProcedureReturn ip
EndProcedure
If InitNetwork()
IPcount = getIPs()
If IPcount
A$ = "IP´s available on: "+Chr(13)+Chr(13)+Chr(34)+localIPs$(0)+Chr(34)+Chr(13)+Chr(13)
For a = 1 To IPcount
A$ + "IP " + Str(a) + " : " + localIPs$(a) + Chr(13)
Next a
Else
A$ = "No IP´s found"
EndIf
MessageRequester("IP INFO",A$,0)
Else
MessageRequester("ERROR","Cant initialize Network!",0)
EndIf
Or just remove this useless lines...
cya,
...Danilo
(registered PureBasic user)
Edited by - Danilo on 16 August 2002 19:21:43
Posted: Fri Aug 16, 2002 2:15 pm
by BackupUser
Restored from previous forum. Originally posted by Franco.
Sorry Danilo, but your code doesn't work on my machine (Win2000-Sp3).
The last 3 digits are:
4294967214
instead of:
174
This is because you have coded:
localIPs$(ip+1)=StrU(PeekB(ipadr.l),0)+"."+StrU(PeekB(ipadr.l+1),0)+"."+StrU(PeekB(ipadr.l+2),0)+"."+StrU(PeekB(ipadr.l+3),2)
instead of:
localIPs$(ip+1)=StrU(PeekB(ipadr.l),0)+"."+StrU(PeekB(ipadr.l+1),0)+"."+StrU(PeekB(ipadr.l+2),0)+"."+StrU(PeekB(ipadr.l+3),0)
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
Posted: Fri Aug 16, 2002 4:09 pm
by BackupUser
Restored from previous forum. Originally posted by tranquil.
@Danielo:
I know that Calc() isn't needed any more but as I coded this procedure strU did not exist in the PB language.
Cheers
Mike
Tranquilizer/ Secretly!
http://www.secretly.de
Registred PureBasic User
Posted: Fri Aug 16, 2002 6:23 pm
by BackupUser
Restored from previous forum. Originally posted by Danilo.
Thx Franco !!
cya,
...Danilo
(registered PureBasic user)