Discussion:
How to get IP address of the interface which the request come through
(too old to reply)
N.A.
2013-03-23 17:13:12 UTC
Permalink
I wan to get the IP address of the interface(network device) which the
request come through.
This information can be easily obtained by

"$c->engine->env->{ SERVER_ADDR }"

with FCGI setting both on nginx/lighttpd web servers.
However SERVER_ADDR is not defined in "Catalyst Test Server."

Of course the network device is usually 'eth0', but in some situation
the network device can be 'virbr0' , 'wlan0','eth1' and so on.
Are there any simple and portable way to get the information.

I use Catalyst of version 5.90020 on linux box.

N.A.
Peter Flanigan
2013-03-23 19:01:08 UTC
Permalink
Post by N.A.
I wan to get the IP address of the interface(network device) which the
request come through.
$c->req->address
--
Regards
Peter Flanigan
2013-03-23 19:03:21 UTC
Permalink
Post by N.A.
I wan to get the IP address of the interface(network device) which the
request come through.
My bad.

Use $c->req->uri->host to get the hostname of the server
--
Regards
N.A.
2013-03-23 19:32:10 UTC
Permalink
Post by Peter Flanigan
Post by N.A.
I wan to get the IP address of the interface(network device) which the
request come through.
My bad.
Use $c->req->uri->host to get the hostname of the server
Sorry, $c->req->uri->host is 'hostname', not a IP.
I want to get IPv4 address like '127.0.0.1' even if I access the page
by 'http://localhost/XXX'


N.A.
Bill Moseley
2013-03-23 23:09:35 UTC
Permalink
T24gU2F0LCBNYXIgMjMsIDIwMTMgYXQgNzozMSBBTSwgTi5BLiA8bi1hQHUwMS5nYXRlMDEuY29t
PiB3cm90ZToKCj4gKDIwMTPlubQwM+aciDIz5pelIDIzOjAzKSwgUGV0ZXIgRmxhbmlnYW4gd3Jv
dGU6Cj4gPiBPbiAyMy8wMy8xMyAxMjoxMiwgTi5BLiB3cm90ZToKPiA+PiBJIHdhbiB0byBnZXQg
dGhlICBJUCBhZGRyZXNzIG9mIHRoZSBpbnRlcmZhY2UobmV0d29yayBkZXZpY2UpIHdoaWNoIHRo
ZQo+ID4+IHJlcXVlc3QgY29tZSB0aHJvdWdoLgo+ID4KPiA+IE15IGJhZC4KPiA+Cj4gPiBVc2Ug
JGMtPnJlcS0+dXJpLT5ob3N0IHRvIGdldCB0aGUgaG9zdG5hbWUgb2YgdGhlIHNlcnZlcgo+ID4K
Pgo+IFNvcnJ5LCAkYy0+cmVxLT51cmktPmhvc3QgaXMgJ2hvc3RuYW1lJywgbm90IGEgSVAuCj4g
SSB3YW50IHRvIGdldCAgSVB2NCBhZGRyZXNzIGxpa2UgJzEyNy4wLjAuMScgZXZlbiBpZiBJIGFj
Y2VzcyB0aGUgcGFnZQo+IGJ5ICdodHRwOi8vbG9jYWxob3N0L1hYWCcKPgoKSW50ZXJlc3Rpbmcu
ICBXaGF0J3MgeW91ciB1c2UgY2FzZSBoZXJlPwoKLS0gCkJpbGwgTW9zZWxleQptb3NlbGV5QGhh
bmsub3JnCi0tLS0tLS0tLS0tLS0tIG5leHQgcGFydCAtLS0tLS0tLS0tLS0tLQpBbiBIVE1MIGF0
dGFjaG1lbnQgd2FzIHNjcnViYmVkLi4uClVSTDogaHR0cDovL2xpc3RzLnNjc3lzLmNvLnVrL3Bp
cGVybWFpbC9jYXRhbHlzdC9hdHRhY2htZW50cy8yMDEzMDMyMy8xYjliMzM3Zi9hdHRhY2htZW50
Lmh0bQo=
N.A.
2013-03-24 05:28:36 UTC
Permalink
Interesting. What's your use case here?
Not a quite common use case.

I make a configuration generation site for Google-android apps.
Each user access the site from their own PC's to generate a
configuration file, and then send the config file to android terminals
over the USB connection.

In my environment, users usually use just a hostname (not a FQDN)
with the help of DNS default search-domain setting.
So they will access URL like 'http://configserver/mk_config', not
a 'http://configserver.domain.co.jp/mk_config.'

However, android OS seems ignore default search-domain setting assigned
by DHCP server, so android-terminals can not resolve IP address
of 'configserver'. (Of course , they can resolve
'configserver.domain.co.jp' to IP address)

This is why I prefer IP's address over hostnames in this situation.


I'm afraid my 'localhost' example is not a appropriate and make you
confused as though I want to resolve 'localhost' to '127.0.0.1'.
Pardon me if this is the case.

N.A
Post by Peter Flanigan
Post by N.A.
I wan to get the IP address of the interface(network device)
which the
Post by Peter Flanigan
Post by N.A.
request come through.
My bad.
Use $c->req->uri->host to get the hostname of the server
Sorry, $c->req->uri->host is 'hostname', not a IP.
I want to get IPv4 address like '127.0.0.1' even if I access the page
by 'http://localhost/XXX'
Interesting. What's your use case here?
--
Bill Moseley
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
Octavian Rasnita
2013-03-24 11:33:41 UTC
Permalink
Post by N.A.
Post by Peter Flanigan
Post by N.A.
I wan to get the IP address of the interface(network device)
which the
Post by Peter Flanigan
Post by N.A.
request come through.
My bad.
Unless there is a more direct way of getting the IP address, you can create
distinct virtual hosts for each IP address that can access your web app and
set an HTTP environment variable that specifies that IP address. Then read
that env var in your app.

--Octavian
N.A.
2013-03-31 10:57:41 UTC
Permalink
Thank you all,

I can't find `more direct way of getting the IP address' nor way of
getting the network interface of the HTTP-request. The following is
summary of what I learned from this ML and source code.


- 'SERVER_ADDR' environment variable is not portable.
PSGI Specification says nothing on this variable.

- It is HTTP server, not the Catalyst who chooses to support
this variable or not.

The lighttpd support 'SERVER_ADDR',
the nginx needs additional configuration to support this, and
HTTP::Server::PSGI(which is used by Catalyst test server) doesn't
support.

- In many cases, host name( '$c->req->uri->host' ) is more suitable
because it is IP version neutral.

N.A.
Post by Octavian Rasnita
Post by N.A.
Post by Peter Flanigan
Post by N.A.
I wan to get the IP address of the interface(network device)
which the
Post by Peter Flanigan
Post by N.A.
request come through.
My bad.
Unless there is a more direct way of getting the IP address, you can
create distinct virtual hosts for each IP address that can access your
web app and set an HTTP environment variable that specifies that IP
address. Then read that env var in your app.
--Octavian
_______________________________________________
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Dev site: http://dev.catalyst.perl.org/
Craig Chant
2013-03-25 14:15:47 UTC
Permalink
ok, perhaps I should read all emails before replying :-)

Morning all ,welcome to the week!

-----Original Message-----
From: Peter Flanigan [mailto:***@roxsoft.co.uk]
Sent: 23 March 2013 14:03
To: The elegant MVC web framework
Subject: Re: [Catalyst] How to get IP address of the interface which the request come through
Post by N.A.
I wan to get the IP address of the interface(network device) which
the request come through.
My bad.

Use $c->req->uri->host to get the hostname of the server

--

Regards

_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended solely for the individual to whom it is addressed. If this Email has been misdirected, please notify the author as soon as possible. If you are not the intended recipient you must not disclose, distribute, copy, print or rely on any of the information contained, and all copies must be deleted immediately. Whilst we take reasonable steps to try to identify any software viruses, any attachments to this e-mail may nevertheless contain viruses, which our anti-virus software has failed to identify. You should therefore carry out your own anti-virus checks before opening any documents. HomeLoan Partnership will not accept any liability for damage caused by computer viruses emanating from any attachment or other document supplied with this e-mail. HomeLoan Partnership reserves the right to monitor and archive all e-mail communications through its network. No representative or employee of HomeLoan Partnership has the authority to enter into any contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by the Financial Services Authority.
Craig Chant
2013-03-25 14:14:28 UTC
Permalink
I use

$c->req->address

-----Original Message-----
From: N.A. [mailto:n-***@u01.gate01.com]
Sent: 23 March 2013 12:13
To: The elegant MVC web framework
Subject: [Catalyst] How to get IP address of the interface which the request come through

I wan to get the IP address of the interface(network device) which the request come through.
This information can be easily obtained by

"$c->engine->env->{ SERVER_ADDR }"

with FCGI setting both on nginx/lighttpd web servers.
However SERVER_ADDR is not defined in "Catalyst Test Server."

Of course the network device is usually 'eth0', but in some situation the network device can be 'virbr0' , 'wlan0','eth1' and so on.
Are there any simple and portable way to get the information.

I use Catalyst of version 5.90020 on linux box.

N.A.

_______________________________________________
List: ***@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/***@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/
This Email and any attachments contain confidential information and is intended solely for the individual to whom it is addressed. If this Email has been misdirected, please notify the author as soon as possible. If you are not the intended recipient you must not disclose, distribute, copy, print or rely on any of the information contained, and all copies must be deleted immediately. Whilst we take reasonable steps to try to identify any software viruses, any attachments to this e-mail may nevertheless contain viruses, which our anti-virus software has failed to identify. You should therefore carry out your own anti-virus checks before opening any documents. HomeLoan Partnership will not accept any liability for damage caused by computer viruses emanating from any attachment or other document supplied with this e-mail. HomeLoan Partnership reserves the right to monitor and archive all e-mail communications through its network. No representative or employee of HomeLoan Partnership has the authority to enter into any contract on behalf of HomeLoan Partnership by email. HomeLoan Partnership is a trading name of H L Partnership Limited, registered in England and Wales with Registration Number 5011722. Registered office: 26-34 Old Street, London, EC1V 9QQ. H L Partnership Limited is authorised and regulated by the Financial Services Authority.
Continue reading on narkive:
Loading...