1. How do I get my own IP address?
- Posted by axtens Sep 21, 2009
- 2351 views
I'm trying to create a UDP client which sends its IP address and %COMPUTERNAME% every five minutes or so. Everything I can do except figure out how to get the sending machine's IP. Any ideas?
Bruce.
2. Re: How do I get my own IP address?
- Posted by euphoric (admin) Sep 21, 2009
- 2392 views
I'm trying to create a UDP client which sends its IP address and %COMPUTERNAME% every five minutes or so. Everything I can do except figure out how to get the sending machine's IP. Any ideas?
Try one of these Euphoria libs. Maybe one of them has a provision for getting the IP address of the host PC.
3. Re: How do I get my own IP address?
- Posted by ghaberek (admin) Sep 21, 2009
- 2374 views
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
4. Re: How do I get my own IP address?
- Posted by jeremy (admin) Sep 21, 2009
- 2371 views
This gets increasingly tricky when your computer has multiple nic cards/interfaces
Jeremy
5. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2349 views
To get your external ip address which the rest of the world sees, set up a short php script on a remote http host to return the contacting ip (that would be you) when you http to it. Keep in mind your isp may change that out from under you at any time, and your router - switch - modem - hub may block all contacts which originate from the outside world.
useless
6. Re: How do I get my own IP address?
- Posted by jeremy (admin) Sep 21, 2009
- 2387 views
To get your external ip address which the rest of the world sees, set up a short php script on a remote http host to return the contacting ip (that would be you) when you http to it. Keep in mind your isp may change that out from under you at any time, and your router - switch - modem - hub may block all contacts which originate from the outside world.
If it's your External IP address (i.e. that your router, cable modem, etc...) may have, you can use get_url() on http://www.whatismyip.com/ and do a bit of text parsing. A bit more work each time than what Kat is suggesting, but you don't have to have an external server running (not sure of your resources).
Jeremy
7. Re: How do I get my own IP address?
- Posted by CoJaBo Sep 21, 2009
- 2533 views
To get your external ip address which the rest of the world sees, set up a short php script on a remote http host to return the contacting ip (that would be you) when you http to it. Keep in mind your isp may change that out from under you at any time, and your router - switch - modem - hub may block all contacts which originate from the outside world.
If it's your External IP address (i.e. that your router, cable modem, etc...) may have, you can use get_url() on http://www.whatismyip.com/ and do a bit of text parsing. A bit more work each time than what Kat is suggesting, but you don't have to have an external server running (not sure of your resources).
Jeremy
Why do text parsing? They have an API: http://www.whatismyip.com/automation/n09230945.asp
8. Re: How do I get my own IP address?
- Posted by jeremy (admin) Sep 21, 2009
- 2516 views
Why do text parsing? They have an API: http://www.whatismyip.com/automation/n09230945.asp
Or use the API they offer
Jeremy
9. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2324 views
This gets increasingly tricky when your computer has multiple nic cards/interfaces
Jeremy
So spill it?
useless
10. Re: How do I get my own IP address?
- Posted by ghaberek (admin) Sep 21, 2009
- 2337 views
This gets increasingly tricky when your computer has multiple nic cards/interfaces
So spill it?
I think he means that the list of IP addresses could contain multiple IPs...
{ "example-computer", "", { "192.168.1.90", "172.20.1.128", "10.1.0.37" }, 2 }
-Greg
11. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2311 views
This gets increasingly tricky when your computer has multiple nic cards/interfaces
So spill it?
I think he means that the list of IP addresses could contain multiple IPs...
{ "example-computer", "", { "192.168.1.90", "172.20.1.128", "10.1.0.37" }, 2 }
-Greg
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.
useless
12. Re: How do I get my own IP address?
- Posted by jeremy (admin) Sep 21, 2009
- 2306 views
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
13. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2307 views
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?
... and by using what Eu code.
useless
14. Re: How do I get my own IP address?
- Posted by ChrisB (moderator) Sep 21, 2009
- 2497 views
Why do text parsing? They have an API: http://www.whatismyip.com/automation/n09230945.asp
Now that's really useful, I never knew that existed, thanks.
Chris
15. Re: How do I get my own IP address?
- Posted by jimcbrown (admin) Sep 21, 2009
- 2331 views
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:
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.
... 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.
16. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2331 views
- Last edited Sep 25, 2009
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.note
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:
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
[/quote]
So by running that code, and not printing out the ip, i have selected which nic the computer will use to send my http request to the world? I fail to see how that will happen.
Filter on or filter out the 192.168.1.90, etc.
... 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.
Again, how does printing this out, or not print it out, tell winxp which nic to talk to the outside world with?
useless
17. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2296 views
$%^#%^&@$%^!$ ^!#%B@!$ Y$@#$ creole.
...jimcbrown said stuff about printing out data to the screen....
So by running that code, and not printing out the ip, i have selected which nic the computer will use to send my http request to the world? I fail to see how that will happen.
Again, how does printing this out, or not print it out, tell winxp which nic to talk to the outside world with?
useless
18. Re: How do I get my own IP address?
- Posted by jimcbrown (admin) Sep 21, 2009
- 2300 views
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
Again, how does printing this out, or not print it out, tell winxp which nic to talk to the outside world with?
useless
I did not print it out. Once you have filtered the ips, you can pick what is left and then tell linux which ip to use to connect from in the connect(2) call via the struct sockaddr.
On xp the function and structs are different, but winsock has the same feature. So once you've filtered out the local ips, you will have the one external ip that you will pass to the OS to connect from or bind to.
However, if the computer has multiple external ips, it gets tricky. You either have to pick one at random, or pick the first in the list, or pick last in the list. If using bind(2), it may be possible to bind using all ips addresses by looping through each one and bind()ing separately. Then you will have to listen on multiple sockets for a client connection.
19. Re: How do I get my own IP address?
- Posted by jeremy (admin) Sep 21, 2009
- 2299 views
Again, how does printing this out, or not print it out, tell winxp which nic to talk to the outside world with?
I'm lost as to what you want to do. Please restate what you want to accomplish.
Jeremy
20. Re: How do I get my own IP address?
- Posted by jimcbrown (admin) Sep 21, 2009
- 2279 views
$%^#%^&@$%^!$ ^!#%B@!$ Y$@#$ creole.
...jimcbrown said stuff about printing out data to the screen....
So by running that code, and not printing out the ip, i have selected which nic the computer will use to send my http request to the world? I fail to see how that will happen.
Again, how does printing this out, or not print it out, tell winxp which nic to talk to the outside world with?
useless
Simple. It doesn't. You have to pass the ip to use to the OS level socket command. This code helps you figure out which ip(s) to pass.
I'll let Jeremy answer on how to pass the ip to the new 4.0 stdlib connect() function, as when I looked at the code in be_socket.c it wasn't immediately obvious to me.
21. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2273 views
Again, how does printing this out, or not print it out, tell winxp which nic to talk to the outside world with?
I'm lost as to what you want to do. Please restate what you want to accomplish.
Jeremy
Eight computers, each with onboard 10/100 lan and one pci 10/100/1000 lan card. The 100lan goes to a 24port 100switch which also goes to the rest of the house and the internet. The 1000lan pci cards go to a 1000lan switch. This way, the 8 can talk amongst themselves really fast and i don't need to buy a 24port 100/1000 for the entire house. And i can use different filter rules in each switch. So how to tell Eu code which nic to use, based on that code's purpose?
useless
22. Re: How do I get my own IP address?
- Posted by mattlewis (admin) Sep 21, 2009
- 2375 views
Eight computers, each with onboard 10/100 lan and one pci 10/100/1000 lan card. The 100lan goes to a 24port 100switch which also goes to the rest of the house and the internet. The 1000lan pci cards go to a 1000lan switch. This way, the 8 can talk amongst themselves really fast and i don't need to buy a 24port 100/1000 for the entire house. And i can use different filter rules in each switch. So how to tell Eu code which nic to use, based on that code's purpose?
I believe the answer is to use socket:bind, even though it's listed as 'server only.' I say this based upon:
Excerpted from the accepted answer (the one with a check mark):
So how can a client choose what NIC to use? A client can also choose to call bind() if it so desires, after socket() and before connect(). Usually this isn't done simply because connect() will automatically bind an unbound socket in a way that enables access via any NIC (which is usually the desired behaviour), but this auto-binding can be turned off by calling bind() explicitly. In this case, you should specify 0 for the port number to have the OS choose a random port number for you.
Matt
23. Re: How do I get my own IP address?
- Posted by jeremy (admin) Sep 21, 2009
- 2279 views
Eight computers, each with onboard 10/100 lan and one pci 10/100/1000 lan card. The 100lan goes to a 24port 100switch which also goes to the rest of the house and the internet. The 1000lan pci cards go to a 1000lan switch. This way, the 8 can talk amongst themselves really fast and i don't need to buy a 24port 100/1000 for the entire house. And i can use different filter rules in each switch. So how to tell Eu code which nic to use, based on that code's purpose?
I think I mentioned earlier that the you should accept either a command line option or a configuration file in situations where you wish to get very advanced.
Now, when you say based on that code's purpose, what code? I don't know still if you are wanting to run a server, want udp, tcp, to utilize broadcasting or something else even. So, it's still just about impossible to answer your question. This original thread was to simply get a computers local IP address. Maybe you need a new thread for this question?
Jeremy
24. Re: How do I get my own IP address?
- Posted by DerekParnell (admin) Sep 21, 2009
- 2248 views
$%^#%^&@$%^!$ ^!#%B@!$ Y$@#$ creole.
Not creole's fault.
Direct cause: Your incorrect use of quoting tags.
Indirect cause: The forum's quote tag processing.
25. Re: How do I get my own IP address?
- Posted by useless Sep 21, 2009
- 2296 views
$%^#%^&@$%^!$ ^!#%B@!$ Y$@#$ creole.
Not creole's fault.
Direct cause: Your incorrect use of quoting tags.
Indirect cause: The forum's quote tag processing.
Yes, i gathered that much. I urge you to gather the world doesn't need yet another language just to replace the olde email listserv.
useless
Forked into: is markup a good thing?
26. Re: How do I get my own IP address?
- Posted by unkmar Sep 22, 2009
- 2227 views
Belch. I can't read the starting of this thread. What happened to it?
27. Re: How do I get my own IP address?
- Posted by jimcbrown (admin) Sep 22, 2009
- 2269 views
Belch. I can't read the starting of this thread. What happened to it?
What do you mean? It shows up fine for me.