Posted: Sat Aug 17, 2002 4:27 pm
Restored from previous forum. Originally posted by ricardo.
Dosent work on my PC, still void the result.
Dosent work on my PC, still void the result.
http://www.purebasic.com
https://www.purebasic.fr/english/
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
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