List resources on local area network

Share your advanced PureBasic knowledge/code with the community.
Hi-Toro
Enthusiast
Enthusiast
Posts: 270
Joined: Sat Apr 26, 2003 3:23 pm

Re: List resources on local area network

Post by Hi-Toro »

And reverse DNS, to get the hostname from an IP address. Anyone know why Windows takes so long to do this kind of thing? It takes a good few seconds here...

Code: Select all


Procedure.l IntFromAddress (ip$)
	ProcedureReturn inet_addr_ (@ip$)
EndProcedure

Procedure.s AddressFromInt (ip.l)
	ProcedureReturn PeekS (inet_ntoa_ (ip))
EndProcedure

; Create WSA version number (damn, ugly!)... 

high.b = 1: low.b = 1 
wsaversion.w

PokeB (@wsaversion, high) ; Gotta poke major version number into low byte... 
PokeB (@wsaversion + 1, low) ; ... and minor version number into high byte

If WSAStartup_ (wsaversion, wsa.WSAData) = #NOERROR

	ip$ = "192.168.0.2" ; PC on local network
;	ip$ = "212.58.226.79" ; BBC News site (shows "newslb308.telhc.bbc.co.uk" at time of writing)

	ipaddr = IntFromAddress (ip$)
	
	*host.hostent = gethostbyaddr_ (@ipaddr, 4, #AF_INET)

	If *host
		Debug ip$ + " = " + PeekS (*host\h_name)
	Else
		Debug "Error... parse results as per MSDN!"
	EndIf
	
	WSACleanup_ () ; Close Windows sockets stuff...
	
EndIf
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Re: List resources on local area network

Post by SFSxOI »

Hi-Toro wrote:And reverse DNS, to get the hostname from an IP address. Anyone know why Windows takes so long to do this kind of thing? It takes a good few seconds here...

Code: Select all


Procedure.l IntFromAddress (ip$)
	ProcedureReturn inet_addr_ (@ip$)
EndProcedure

Procedure.s AddressFromInt (ip.l)
	ProcedureReturn PeekS (inet_ntoa_ (ip))
EndProcedure

; Create WSA version number (damn, ugly!)... 

high.b = 1: low.b = 1 
wsaversion.w

PokeB (@wsaversion, high) ; Gotta poke major version number into low byte... 
PokeB (@wsaversion + 1, low) ; ... and minor version number into high byte

If WSAStartup_ (wsaversion, wsa.WSAData) = #NOERROR

	ip$ = "192.168.0.2" ; PC on local network
;	ip$ = "212.58.226.79" ; BBC News site (shows "newslb308.telhc.bbc.co.uk" at time of writing)

	ipaddr = IntFromAddress (ip$)
	
	*host.hostent = gethostbyaddr_ (@ipaddr, 4, #AF_INET)

	If *host
		Debug ip$ + " = " + PeekS (*host\h_name)
	Else
		Debug "Error... parse results as per MSDN!"
	EndIf
	
	WSACleanup_ () ; Close Windows sockets stuff...
	
EndIf
almost instant here, not enough delay to even have enough time to say "hmmm"
The advantage of a 64 bit operating system over a 32 bit operating system comes down to only being twice the headache.
Post Reply