hostNameToAddress (too many IP's)

Bringing the internet highway into your project? Building FTP, HTTP, email, chat or other client solutions?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

hostNameToAddress (too many IP's)

Post by trevix » Tue Apr 14, 2009 7:00 pm

Gasp...I used to get the IP address of the computer where the stack is running using "hostnametoaddress(the hostname)".
Then, one day, I did the same on my PowerBook and I've got several IPs (5...the correct one was between them but I do not know how to make RunRev to choose it).
I know that I made this difficult because the setup is this:

Pubblic Address from my provider, Switcher with the PowerBook hardwired to it, the Powerbook has also WiFi enabled (sending ftp data to my AppleTv) with Internet sharing.
I've got 5 address (not always with this list order):

- 10.0.2.1 (?)
- the IP that I need (the one shown on the network Ethernet preferences)
- the IP of the airport network
- 2 moore that I dont understand where they come from

Since I need to get ONLY the Ethernet IP address, how can i get it ?

Thanks

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: hostNameToAddress (too many IP's)

Post by sturgis » Tue Apr 14, 2009 9:44 pm

Hey there. Had a couple thoughts on this.

If the address you want is a public address provided by your isp, and all the rest are private or localhost, then it shouldn't be too bad to eliminate the ones you don't want.

If its a 10. address, ignore it. If its a 192.168 address, ignore that too. If its a 127.0.0.1 address, thats localhost, ignore that one. Theres a 3rd set of private IP addresses, but alas its been so long I don't remember the set, but theres class a, b, and c private addresses, so if you find out the range for those you can eliminate them and the local host and see whats left.

IF the IP you're looking for IS one of the private addresses, there may be another way, assuming you know that you'll always be looking for the same ethernet interface. If thats the case you can execute a shell script (can probably do it from inside your app using do scriptStuff as shell (not sure of the format of that either) and parse the results. For example, execute ifconfig in a shell. I'm using en1 (2nd ethernet port on my mac pro since my first one is flaky). So you find the section starting out en1: then look for a line that says inet right after it. NOT inet6, just inet.
It will look something like this.

Code: Select all

en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	inet 192.168.2.15 netmask 0xffffff00 broadcast 192.168.2.255
If you are making this for public rather than private use, this gets more difficult of course.

Edit: Did a quick search, you can find more info on getting info from external shell commands here.
http://forums.runrev.com/phpBB2/viewtop ... ell+script
Also, if you were doing this on windows, change ifconfig to ipconfig /all and parse accordingly.
endEdit

trevix wrote:Gasp...I used to get the IP address of the computer where the stack is running using "hostnametoaddress(the hostname)".
Then, one day, I did the same on my PowerBook and I've got several IPs (5...the correct one was between them but I do not know how to make RunRev to choose it).
I know that I made this difficult because the setup is this:

Pubblic Address from my provider, Switcher with the PowerBook hardwired to it, the Powerbook has also WiFi enabled (sending ftp data to my AppleTv) with Internet sharing.
I've got 5 address (not always with this list order):

- 10.0.2.1 (?)
- the IP that I need (the one shown on the network Ethernet preferences)
- the IP of the airport network
- 2 moore that I dont understand where they come from

Since I need to get ONLY the Ethernet IP address, how can i get it ?

Thanks

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Post by trevix » Wed Apr 15, 2009 12:55 am

I know...I should have learned at the time about static and dynamic, DNS, pubblic and local, etc ...so bare with me if I am confused.

I'm doing an app to be used by whoever. I need to be sure the app get the correct IP. Most people do not know where to look for the Ip address on their PC o Mac, so I want to present it in a window...

I dont know very much of IP addressing but I believe that the IP to be pinpointed has to be the one accessed from inside a local network AND from ouside (it is a client server application). I think...the local address.

On my G5, hard connected to the same switcher/router I was talking before, with aiport closed, the "hostnametoaddress(the hostname)" report ONLY:
- 28.6.97.99 (correct, since the router is 28.6.97.1)

If I activate Aiport, keeping the Ethernet connection, I've the same "hostnametoaddress(the hostname)":
28.6.97.99

If I activate aiport, keeping the Ethernet connection, but sharing internet I've got:
- 10.0.2.1 (probably the AppleTV)
- 28.6.97.99 (this is the local host)
- 169.254.195.210 (?)

On the powerbook, for some strange reason, I have the 3 IP above (more o less) and 2 more IP (172.16.141.1 and 172.16.247.1)
What a mess.

Since RunRev does such extensive use of internet, I believe there must be a way to get ONLY the IP that, both PC and Mac, shows in the OS network preferences (in my case 28.6.97.99). This should work in any situation (I have opened a socket from outside to this ip with no problems)

Or should I ask the user..."Please go to net preferences and copy down your IP on a piece of paper, then..."
Am I missing something ?

(I did shell commands on Runrev but your code suggestion is way too complex for me)

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Wed Apr 15, 2009 1:46 am

Hmm. Since you can't know ahead of time how a users system is setup, this could be problematic. I'm sure theres a simple solution to this also, but I don't know what it is.

A complicated method would be to build a web page and have your program hit that page and return the ip address. However, if the user is behind a router that does network address translation, the ip you get back will the the IP of the router, not the system behind the router, at which point if you want to be able to initiate communications from the internet side and have your application listening only, then the user would have to have port forwarding in their router on, or set a machine as the dmz which opens up a whole can of security worms.

For those of you who are more up on this sort of thing, am I in the right ball park here?

More information on what you're trying to accomplish, I'm not sure how to assist.

If you're wanting to write a web server type app, it would take knowledge on the part of the end user to configure routers/firewalls etc to allow incoming connections. If you're writing something that is initiating the connection OUTBOUND, then knowing the users IP is much less of an issue.

Hopefully a guru will chime in here with more help.
trevix wrote:I know...I should have learned at the time about static and dynamic, DNS, pubblic and local, etc ...so bare with me if I am confused.

I'm doing an app to be used by whoever. I need to be sure the app get the correct IP. Most people do not know where to look for the Ip address on their PC o Mac, so I want to present it in a window...

I dont know very much of IP addressing but I believe that the IP to be pinpointed has to be the one accessed from inside a local network AND from ouside (it is a client server application). I think...the local address.

On my G5, hard connected to the same switcher/router I was talking before, with aiport closed, the "hostnametoaddress(the hostname)" report ONLY:
- 28.6.97.99 (correct, since the router is 28.6.97.1)

If I activate Aiport, keeping the Ethernet connection, I've the same "hostnametoaddress(the hostname)":
28.6.97.99

If I activate aiport, keeping the Ethernet connection, but sharing internet I've got:
- 10.0.2.1 (probably the AppleTV)
- 28.6.97.99 (this is the local host)
- 169.254.195.210 (?)

On the powerbook, for some strange reason, I have the 3 IP above (more o less) and 2 more IP (172.16.141.1 and 172.16.247.1)
What a mess.

Since RunRev does such extensive use of internet, I believe there must be a way to get ONLY the IP that, both PC and Mac, shows in the OS network preferences (in my case 28.6.97.99). This should work in any situation (I have opened a socket from outside to this ip with no problems)

Or should I ask the user..."Please go to net preferences and copy down your IP on a piece of paper, then..."
Am I missing something ?

(I did shell commands on Runrev but your code suggestion is way too complex for me)

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Wed Apr 15, 2009 9:25 am

Hi,

wouldnt it help to call:
http://checkip.dyndns.org/

I found this for an applescript:
(do shell script "curl http://checkip.dyndns.org/ | grep 'Current IP Address'")

put shell ("curl http://checkip.dyndns.org/") in the message box returned:


% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed

100 107 100 107 0 0 2844 0 --:--:-- --:--:-- --:--:-- 2844
100 107 100 107 0 0 2724 0 --:--:-- --:--:-- --:--:-- 0
<html><head><title>Current IP Check</title></head><body>Current IP Address: 193.175.243.233</body></html>

regards

Bernd

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Post by trevix » Wed Apr 15, 2009 12:53 pm

Yes, the "checkip" shell script works for the external IP, thanks...but let me explain:
I'm doing a Windows/Osx client/server calendar for small companies, where the server records event datas on a commercial database. (In this explanation off course "Server" is the "calendar server application", "Client" is the "calendar client application".)

The server sits on the company server or a computer in the intranet, togheter with the database.
The clients are on local network computers or sits outside and connect trough internet.

In order to connect, I've choosen to have the server admin to write every user IP (and name and PW) in the calendar server preferences.
The clients have to write the server IP on the calendar client preferences.

So, there is no problem for the server administrator to voice-communicate the IP of the server to the clients so that they can connect (he knows where to look).
But I would like the clients to easily see their IP on a presented Runrev window.
What also if the Ip is static ? What happens ? The "Checkip" is the external, but each computer on the intranet will still have a local IP
--------------

For what I know, most of them will have a Dynamic external address (by their ISP), a router and a number of internal IPs (for each client and server)
So i guess I need each PC to find their "internal" IP.

But it all fits down to this: On the OS network preferences both on Windows and OSX it is shown the IP that I need. How can I get it ?
(as I said before, the "hostanametoaddress" gets it, but with other IPs that I do not know with which rule to parse)

Thanks for any help

trevix
Posts: 1064
Joined: Sat Feb 24, 2007 11:25 pm
Contact:

Post by trevix » Wed Apr 15, 2009 1:05 pm

UUUUH...
I found this, on the runrev mail archive:

Code: Select all

on mouseUp
   put "255.255.255.255:43222" into testSock
   open datagram socket to testSock  -- opens immediately on Win2K
   put hostAddress(testSock) into msg
   close socket testSock
end mouseUp
Works on OSX and it parse all the other IPs. I have not tried it yet on Windows.
Do you guys thinks it is reliable in any situation ? What if there is a blocking firewall ?

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Post by sturgis » Wed Apr 15, 2009 4:51 pm

I think this is where I'm starting to get confused :oops:

Ok. based on your scenario description, you have a server. No problem. If the server is on an intranet, and all clients are connecting from the same intranet, to the server there should be no real gateway issues, and all clients should have a unique (to the intranet) private IP. If all clients have a public IP, then there is no real problem either, though it would be a security nightmare.

Say the private ip of your intranet had a range of 192.168.1.1 to 192.168.1.254.. If you add in outside users who are behind a nat using the same range, there can be duplicate IPs IE 192.168.1.25 coming from several different locations. So that isn't really a useful number to know.

Then there is the nat gateway itself. If they are hitting your server from outside, and say there are 3 computers behind the nat, then each system could have an address in the same range also, so you could have 192.168.1. 10,11,12 so each of those would have their own unique internal, the problem of course being they could match ips of other networks internal nat ips. Again this really doesn't matter, its just that it doesn't seem that having this information would really be useful.

YOU could have the server return the perceived address when they connect, but again this can be wierd. If there are 3 systems behind a nat gateway, then the ip the server would see is that of the gateway itself. If I understand this part correctly, packets are tagged by the mac address of the internal system itself, allowing the nat gateway to know where to send returning packets based on mac address, not ip. Is there a heavy duty network person that can confirm this?

What all this boils down to, is that if I want to run apache web server for example and have it accessible from the outside, knowing my private internal ip is just a small step to getting this setup. In addition I have to make sure my dsl box is configured to forward port 80, AND my internal nat gateway has to be configured also, either using port forwarding, or setting up a dmz. Which brings us back to the issue with multiple computers behind a nat gateway. As far as I know you can setup 1 machine as dmz where everything is forwarded, so you couldn't easily hit the additional machines. Same with port forwarding I believe.

If you just want to display a clients IP just to display it, then I'd say the last code you posted is fine.

I have one question regarding all this stuff myself. How does push work? It seems to me that the client has to maintain some type of tenuous contact with a server for push to work.. Initially instigated by the client. Do I misunderstand this? Then when there is a server change, it shoves the changes down to the client using that already existing connect.

If I DO misunderstand this, (which is likely) could someone help clarify? Perhaps push technology is where your questions are headed trevix.

trevix wrote:Yes, the "checkip" shell script works for the external IP, thanks...but let me explain:
I'm doing a Windows/Osx client/server calendar for small companies, where the server records event datas on a commercial database. (In this explanation off course "Server" is the "calendar server application", "Client" is the "calendar client application".)

The server sits on the company server or a computer in the intranet, togheter with the database.
The clients are on local network computers or sits outside and connect trough internet.

In order to connect, I've choosen to have the server admin to write every user IP (and name and PW) in the calendar server preferences.
The clients have to write the server IP on the calendar client preferences.

So, there is no problem for the server administrator to voice-communicate the IP of the server to the clients so that they can connect (he knows where to look).
But I would like the clients to easily see their IP on a presented Runrev window.
What also if the Ip is static ? What happens ? The "Checkip" is the external, but each computer on the intranet will still have a local IP
--------------

For what I know, most of them will have a Dynamic external address (by their ISP), a router and a number of internal IPs (for each client and server)
So i guess I need each PC to find their "internal" IP.

But it all fits down to this: On the OS network preferences both on Windows and OSX it is shown the IP that I need. How can I get it ?
(as I said before, the "hostanametoaddress" gets it, but with other IPs that I do not know with which rule to parse)

Thanks for any help

Post Reply