Re: How do I get my own IP address?

new topic     » goto parent     » topic index » view thread      » older message » newer message
eukat said...
jeremy said...
eukat said...

I didn't mean to ask for a definition, i was trying to convey the meaning of the word "how" when i asked him to "spill it". In what way or manner or by what method does Jeremy specify which nic to use to contact the world outside the computer, and by using what Eu code.

Hm, contacting the world outside the computer is not so hard. To allow the outside world to connect to you is not so hard either, just bind to 0.0.0.0. Now, when it comes to binding only to a particular address of the many available, you pretty much have to have a config file and let the user choose or specify on the command line.

All of that, though, is not determining your local address. If you truly need to do that intelligently, then you need to filter out some common standards such as 192...., 10..., etc...

Jeremy

Filter in what where?

From Greg's eucode:

ghaberek said...

This might work for you:

include std/pretty.e 
include std/net/dns.e 
 
constant COMPUTERNAME = getenv("COMPUTERNAME") 
pretty_print( 1, host_by_name(COMPUTERNAME), {2} ) 

{ 
  "example-computer", 
  "", 
  { 
    "192.168.1.90" 
  }, 
  2 
} 


-Greg

Filter on or filter out the 192.168.1.90, etc.

eukat said...
eukat said...

... and by using what Eu code.

Untested concept code:

include std/pretty.e 
include std/net/dns.e 
 
constant COMPUTERNAME = getenv("COMPUTERNAME") 
sequence ips = host_by_name(COMPUTERNAME) 
for i = 1 to length(ips[3]) do 
	if match("192.", ips[3][i]) = 1 then 
		-- filter 
	elsif match("10.", ips[3][i]) = 1 then 
		-- filter 
	-- and so on 
	end if 
end for 

Note: I did not look up the output format of host_by_name()'s return value.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu