Figuring out external IP addresses of network interfaces

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Figuring out external IP addresses of network interfaces

Hari
Hi All,

I was wondering if there is a way to figure out the IP addresses of various network interfaces on a host machine. I've looked at some traffic on the list from a few years ago (6-7 years ago) that appeared to indicate there was no way to do this. As far as I could tell, there was a workaround using (running regularly) shell script that would write interface information to a file that could then be scooped up by the image.

I was wondering if things have changed.

I'd like an application to be aware of and be able to provide the IP address and port it is listening on for requests from the outside world (not localhost.)

Thanks in advance.

Kind regards,

Hari




Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Edgar De Cleene
YES
You could know your local and internet Ip

I have this in Work (PasteUpMorph)
reportPublicIP
"Report the public IP of this computer
World reportPublicIP."

| addrString m s stream |
stream := HTTPSocket httpGet: 'http://checkip.dyndns.com'.
stream upToAll: 'IP Address: '.
stream := stream upTo: $<.
Socket initializeNetwork.
addrString := stream upTo: $<.
m := RectangleMorph new
color: (Color r: 0.6 g: 0.8 b: 0.6);
extent: 118@36;
borderWidth: 1.
s := StringMorph contents: 'Public IP:'.
s position: m position + (5@4).
m addMorph: s.
s := StringMorph contents: addrString.
s position: m position + (5@19).
m addMorph: s.
self primaryHand attachMorph: m.

For local
 Transcript show: NetNameResolver localHostAddress printString

On Mar 4, 2017, at 14:40, Hari Balaraman <[hidden email]> wrote:

Hi All,

I was wondering if there is a way to figure out the IP addresses of various network interfaces on a host machine. I've looked at some traffic on the list from a few years ago (6-7 years ago) that appeared to indicate there was no way to do this. As far as I could tell, there was a workaround using (running regularly) shell script that would write interface information to a file that could then be scooped up by the image.

I was wondering if things have changed.

I'd like an application to be aware of and be able to provide the IP address and port it is listening on for requests from the outside world (not localhost.)

Thanks in advance.

Kind regards,

Hari






Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

John Pfersich-2
You can always use OSProcess/CommandShell to run netstat on Linux and MacOS. Do a search for OSProcess for more information. 

Sent from my iPhone

On Mar 4, 2017, at 12:21, Edgar De Cleene <[hidden email]> wrote:

YES
You could know your local and internet Ip

I have this in Work (PasteUpMorph)
reportPublicIP
"Report the public IP of this computer
World reportPublicIP."

| addrString m s stream |
stream := HTTPSocket httpGet: 'http://checkip.dyndns.com'.
stream upToAll: 'IP Address: '.
stream := stream upTo: $<.
Socket initializeNetwork.
addrString := stream upTo: $<.
m := RectangleMorph new
color: (Color r: 0.6 g: 0.8 b: 0.6);
extent: 118@36;
borderWidth: 1.
s := StringMorph contents: 'Public IP:'.
s position: m position + (5@4).
m addMorph: s.
s := StringMorph contents: addrString.
s position: m position + (5@19).
m addMorph: s.
self primaryHand attachMorph: m.

For local
 Transcript show: NetNameResolver localHostAddress printString

On Mar 4, 2017, at 14:40, Hari Balaraman <[hidden email]> wrote:

Hi All,

I was wondering if there is a way to figure out the IP addresses of various network interfaces on a host machine. I've looked at some traffic on the list from a few years ago (6-7 years ago) that appeared to indicate there was no way to do this. As far as I could tell, there was a workaround using (running regularly) shell script that would write interface information to a file that could then be scooped up by the image.

I was wondering if things have changed.

I'd like an application to be aware of and be able to provide the IP address and port it is listening on for requests from the outside world (not localhost.)

Thanks in advance.

Kind regards,

Hari







Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Ron Teitelbaum
In reply to this post by Edgar De Cleene
HI all,

if you are running a web server you can use this to replace the http://checkip.dyndns.com suggested by Edgar (Hi Edgar!):

<?php
$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');
echo trim($ip);?>
 
This does a pretty good job of reporting back the IP address of a connection from php.  I was using https://api.ipify.org/ but a number of companies wrongly reported that as a virus and blocked it.  Having your own code make it easier to get people to allow the connection especially if they are adjusting proxy servers for your server addresses anyway.  

I use the client IP address to calculate the distance from the client connecting to each server so that I can select the closest one and reduce latency.  

All the best,

Ron Teitelbaum



On Sat, Mar 4, 2017 at 3:21 PM Edgar De Cleene <[hidden email]> wrote:
YES
You could know your local and internet Ip

I have this in Work (PasteUpMorph)
reportPublicIP
"Report the public IP of this computer
World reportPublicIP."

| addrString m s stream |
stream := HTTPSocket httpGet: 'http://checkip.dyndns.com'.
stream upToAll: 'IP Address: '.
stream := stream upTo: $<.
Socket initializeNetwork.
addrString := stream upTo: $<.
m := RectangleMorph new
color: (Color r: 0.6 g: 0.8 b: 0.6);
extent: 118@36;
borderWidth: 1.
s := StringMorph contents: 'Public IP:'.
s position: m position + (5@4).
m addMorph: s.
s := StringMorph contents: addrString.
s position: m position + (5@19).
m addMorph: s.
self primaryHand attachMorph: m.

For local
 Transcript show: NetNameResolver localHostAddress printString

On Mar 4, 2017, at 14:40, Hari Balaraman <[hidden email]> wrote:

Hi All,

I was wondering if there is a way to figure out the IP addresses of various network interfaces on a host machine. I've looked at some traffic on the list from a few years ago (6-7 years ago) that appeared to indicate there was no way to do this. As far as I could tell, there was a workaround using (running regularly) shell script that would write interface information to a file that could then be scooped up by the image.

I was wondering if things have changed.

I'd like an application to be aware of and be able to provide the IP address and port it is listening on for requests from the outside world (not localhost.)

Thanks in advance.

Kind regards,

Hari






Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Edgar De Cleene


On Mar 5, 2017, at 01:46, Ron Teitelbaum <[hidden email]> wrote:

I use the client IP address to calculate the distance from the client connecting to each server so that I can select the closest one and reduce latency.  


Hi Ron.
Could you elaborate more?.
I


Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

David T. Lewis
In reply to this post by John Pfersich-2
On Sat, Mar 04, 2017 at 08:47:03PM -0800, John Pfersich wrote:
> You can always use OSProcess/CommandShell to run netstat on Linux and MacOS. Do a search for OSProcess for more information.
>

As luck would have it, I just updated the SqueakMap entries for OSProcess
and CommandShell yesterday, so you can easily install them from SqueakMap.
Please use the latest versions of OSProcess/CommandShell regardless of what
version of Squeak you have.

Repositories:
  http://www.squeaksource.com/OSProcess
  http://www.squeaksource.com/CommandShell

Information:
  http://wiki.squeak.org/squeak/708
  http://wiki.squeak.org/squeak/1914
  http://wiki.squeak.org/squeak/6023

Dave


> Sent from my iPhone
>
> > On Mar 4, 2017, at 12:21, Edgar De Cleene <[hidden email]> wrote:
> >
> > YES
> > You could know your local and internet Ip
> >
> > I have this in Work (PasteUpMorph)
> > reportPublicIP
> > "Report the public IP of this computer
> > World reportPublicIP."
> >
> > | addrString m s stream |
> > stream := HTTPSocket httpGet: 'http://checkip.dyndns.com'.
> > stream upToAll: 'IP Address: '.
> > stream := stream upTo: $<.
> >
> > Socket initializeNetwork.
> > addrString := stream upTo: $<.
> > m := RectangleMorph new
> > color: (Color r: 0.6 g: 0.8 b: 0.6);
> > extent: 118@36;
> > borderWidth: 1.
> > s := StringMorph contents: 'Public IP:'.
> > s position: m position + (5@4).
> > m addMorph: s.
> > s := StringMorph contents: addrString.
> > s position: m position + (5@19).
> > m addMorph: s.
> > self primaryHand attachMorph: m.
> >
> > For local
> >  Transcript show: NetNameResolver localHostAddress printString
> >
> >> On Mar 4, 2017, at 14:40, Hari Balaraman <[hidden email]> wrote:
> >>
> >> Hi All,
> >>
> >> I was wondering if there is a way to figure out the IP addresses of various network interfaces on a host machine. I've looked at some traffic on the list from a few years ago (6-7 years ago) that appeared to indicate there was no way to do this. As far as I could tell, there was a workaround using (running regularly) shell script that would write interface information to a file that could then be scooped up by the image.
> >>
> >> I was wondering if things have changed.
> >>
> >> I'd like an application to be aware of and be able to provide the IP address and port it is listening on for requests from the outside world (not localhost.)
> >>
> >> Thanks in advance.
> >>
> >> Kind regards,
> >>
> >> Hari
> >>
> >>
> >>
> >>
> >
> >

>


Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Ron Teitelbaum
In reply to this post by Edgar De Cleene
Hi Edgar,

You can use the IP Address to get a location.  We use http://freegeoip.net, then you just need to do some math to get the distance.  http://www.movable-type.co.uk/scripts/latlong.html 

Here is more info on what we are using it for http://www.3dicc.com/immersive-terf-global-router-framework/ 

All the best,

Ron Teitelbaum





On Sun, Mar 5, 2017 at 2:25 AM Edgar De Cleene <[hidden email]> wrote:


On Mar 5, 2017, at 01:46, Ron Teitelbaum <[hidden email]> wrote:

I use the client IP address to calculate the distance from the client connecting to each server so that I can select the closest one and reduce latency.  


Hi Ron.
Could you elaborate more?.
I



Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Hari
In reply to this post by Edgar De Cleene
Thanks Edgar, Ron, John, David, for the excellent suggestions!
Kind regards,
Hari
Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Edgar De Cleene
In reply to this post by Ron Teitelbaum
Very thanks, is very valuable info to me.

On Mar 5, 2017, at 11:49, Ron Teitelbaum <[hidden email]> wrote:

Hi Edgar,

You can use the IP Address to get a location.  We use http://freegeoip.net, then you just need to do some math to get the distance.  http://www.movable-type.co.uk/scripts/latlong.html 

Here is more info on what we are using it for http://www.3dicc.com/immersive-terf-global-router-framework/ 

All the best,

Ron Teitelbaum





On Sun, Mar 5, 2017 at 2:25 AM Edgar De Cleene <[hidden email]> wrote:


On Mar 5, 2017, at 01:46, Ron Teitelbaum <[hidden email]> wrote:

I use the client IP address to calculate the distance from the client connecting to each server so that I can select the closest one and reduce latency.  


Hi Ron.
Could you elaborate more?.
I





Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Ron Teitelbaum

You are very welcome! 

Ron


On Sun, Mar 5, 2017, 1:19 PM Edgar De Cleene <[hidden email]> wrote:
Very thanks, is very valuable info to me.

On Mar 5, 2017, at 11:49, Ron Teitelbaum <[hidden email]> wrote:

Hi Edgar,

You can use the IP Address to get a location.  We use http://freegeoip.net, then you just need to do some math to get the distance.  http://www.movable-type.co.uk/scripts/latlong.html 

Here is more info on what we are using it for http://www.3dicc.com/immersive-terf-global-router-framework/ 

All the best,

Ron Teitelbaum





On Sun, Mar 5, 2017 at 2:25 AM Edgar De Cleene <[hidden email]> wrote:


On Mar 5, 2017, at 01:46, Ron Teitelbaum <[hidden email]> wrote:

I use the client IP address to calculate the distance from the client connecting to each server so that I can select the closest one and reduce latency.  


Hi Ron.
Could you elaborate more?.
I





Reply | Threaded
Open this post in threaded view
|

Re: Figuring out external IP addresses of network interfaces

Frank Shearar-3
In reply to this post by Hari
On 4 March 2017 at 09:40, Hari Balaraman <[hidden email]> wrote:
Hi All,

I was wondering if there is a way to figure out the IP addresses of various network interfaces on a host machine. I've looked at some traffic on the list from a few years ago (6-7 years ago) that appeared to indicate there was no way to do this. As far as I could tell, there was a workaround using (running regularly) shell script that would write interface information to a file that could then be scooped up by the image.

I was wondering if things have changed.

I'd like an application to be aware of and be able to provide the IP address and port it is listening on for requests from the outside world (not localhost.)

Thanks in advance.

Kind regards,

Hari


I'm unaware of any Squeak library doing this, but sounds like you want an FFI interface to the iphlpapi DLL, on a Windows box. That will let you iterate over interfaces, addresses of interfaces, and so on. It's in Delphi, but you can see the APIs can be used here: https://github.com/frankshearar/SipStack/blob/master/src/IdNetworking.pas

frank