Just starting out? Need help? Post your questions and find answers here.
BackupUser
PureBasic Guru
Posts: 16777133 Joined: Tue Apr 22, 2003 7:42 pm
Post
by BackupUser » Sun Aug 18, 2002 9:45 am
Restored from previous forum. Originally posted by fred .
Another little ip enumerator I got on my PC:
Code: Select all
Structure HOSTENT
h_name.l
h_aliases.l
h_addrtype.w
h_length.w
h_addr_list.l
EndStructure
If InitNetwork()
Hostname$ = Space(255)
gethostname_(Hostname$,255)
Debug "Hostname: "+Hostname$
pHostinfo = gethostbyname_(Hostname$)
If pHostinfo = 0
Debug "Unable to resolve domain name."
Else
CopyMemory (pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT))
If hostinfo\h_addrtype #AF_INET
Debug "A non-IP address was returned."
Else
While PeekL(hostinfo\h_addr_list+AdressNumber*4)
ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4)
Debug StrU(PeekB(ipAddress),0)+"."+StrU(PeekB(ipAddress+1),0)+"."+StrU(PeekB(ipAddress+2),0)+"."+StrU(PeekB(ipAddress+3),0)
AdressNumber+1
Wend
EndIf
EndIf
Else
Debug "Network can't be initialized"
EndIf
Fred - AlphaSND
BackupUser
PureBasic Guru
Posts: 16777133 Joined: Tue Apr 22, 2003 7:42 pm
Post
by BackupUser » Sun Aug 18, 2002 9:51 am
Restored from previous forum. Originally posted by ricardo .
This one works : )
Thanks !!
BackupUser
PureBasic Guru
Posts: 16777133 Joined: Tue Apr 22, 2003 7:42 pm
Post
by BackupUser » Sun Aug 18, 2002 5:50 pm
Restored from previous forum. Originally posted by Franco .
Hmm, that's strange...
Tranquil's/Danilo's code works with W2K-Sp3 but not on WinXP.
Fred's code works on WinXP, but have to test it tomorrow @work on W2K-Sp3 though.
Have a nice day...
Franco
Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
Posts: 16777133 Joined: Tue Apr 22, 2003 7:42 pm
Post
by BackupUser » Sun Aug 18, 2002 8:25 pm
Restored from previous forum. Originally posted by Danilo .
Now put that in a procedure...
Code: Select all
IPmax = 10
Dim localips$(IPmax)
Procedure.l getIPs()
;
; [IN] = nothing
;
; [OUT] = ProcedureReturn = numbers of IPs found ( -1 when IPmax too small )
; localIPs$(0) = Hostname
; localIPs$(1+) = all IPs
;
Structure HOSTENT
h_name.l
h_aliases.l
h_addrtype.w
h_length.w
h_addr_list.l
EndStructure
Shared localIPs$,IPmax
Hostname$ = Space(1024)
Dim localIPs$(IPmax) ; Remove all existent IPs from list ( REDIM = Clear )
gethostname_(@Hostname$,1024)
localIPs$(0) = UCase(PeekS(@Hostname$))
pHostinfo = gethostbyname_(@Hostname$)
If pHostinfo = 0
; MessageRequester("ERROR", "Unable To resolve domain name.",0)
ProcedureReturn 0
Else
CopyMemory(pHostinfo, hostinfo.HOSTENT, SizeOf(HOSTENT))
If hostinfo\h_addrtype #AF_INET
; MessageRequester("ERROR","A non-IP address was returned.",0)
ProcedureReturn 0
Else
While PeekL(hostinfo\h_addr_list+AdressNumber*4)
ipAddress = PeekL(hostinfo\h_addr_list+AdressNumber*4)
If AdressNumber 0
A$ = "IP´s available on: "+Chr(34)+localIPs$(0)+Chr(34)+" = "+Str(IPcount)+Chr(13)+Chr(13)
For a = 1 To IPcount
A$ + "IP " + Str(a) + " : " + localIPs$(a) + Chr(13)
Next a
Else
If IPcount = -1 : A$ = "IPmax too small"
Else : A$ = "No IP´s found" : EndIf
EndIf
MessageRequester("IP INFO",A$,0)
Else
MessageRequester("ERROR","Cant initialize Network!",0)
EndIf
cya,
...Danilo
(registered PureBasic user)