Client IP Address from Request Header in Rails - ruby-on-rails-3

Can I access the IP address of the client from request header?If yes,how?

Yes you can.
visitor_ip = request.env['REMOTE_ADDR']

Related

.net core get RemoteIpAddress.MapToIPv4() that is behind cloudflare proxy

I need to extract the user IP address (v4).
I have the following code to do so:
HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString();
The problem is that in this case I am getting cloud flare ip address.
How can I get the forwarded v4 IP address?
Thanks
Cloudflare passes all HTTP request headers to your origin web server and adds additional headers.
The header:
CF-Connecting-IP
provides the client IP address connecting to Cloudflare to the origin
web server.
You can also use the header:
X-Forwarded-For
which maintains proxy server and original visitor IP addresses.
For more information about the CloudFlare headers you can refer to the documentation
Actually, you can created a method that tries to check all these headers and return the client IP address value.
private string getRemoteIpAddress(HttpContext accessor) {
// try reading the CloudFlare client IP address header
if (!string.IsNullOrEmpty(accessor.Request.Headers["CF-CONNECTING-IP"]))
return accessor.Request.Headers["CF-CONNECTING-IP"];
// try reading the proxy server and original visitor IP addresses header
var ipAddress = accessor.GetServerVariable("HTTP_X_FORWARDED_FOR");
if (!string.IsNullOrEmpty(ipAddress)) {
var addresses = ipAddress.Split(',');
if (addresses.Length != 0) return addresses.Last();
}
// try reading the remote IpAddress without a proxy
return accessor.Connection.RemoteIpAddress.ToString();
}

How to make HTTPS request from mule ESB?

How to make HTTPS request without port from HTTP component ? I can't use url with port 443 or 80 because port number just appending with url and it says invalid url.
So how to make request just with URL instead of enter port number ?
Also, If i have IP address i can use IP + Port to access the data. but Server runs behind proxy server so no way to find application server IP.
Error Message:
Message : Error sending HTTP request to https://xxx-yyy.com:443/rest/name
Payload : {NullPayload}
Payload Type : org.mule.transport.NullPayload
Root Exception stack trace:
java.util.NoSuchElementException
at java.util.Collections$EmptyIterator.next(Unknown Source)
at com.mulesoft.mule.http.request.NameResolvingRequestBuilder.nextResolvedAddresses(NameResolvingRequestBuilder.java:99)
at com.mulesoft.mule.http.request.NameResolvingRequestBuilder.setUrl(NameResolvingRequestBuilder.java:75)
at org.mule.module.http.internal.request.grizzly.GrizzlyHttpClient.createGrizzlyRequest(GrizzlyHttpClient.java:555)
at org.mule.module.http.internal.request.grizzly.GrizzlyHttpClient.sendAndWait(GrizzlyHttpClient.java:355)
at org.mule.module.http.internal.request.grizzly.GrizzlyHttpClient.send(GrizzlyHttpClient.java:303)
at com.mulesoft.mule.http.request.grizzly.EEGrizzlyHttpClient.send(EEGrizzlyHttpClient.java:105)
at org.mule.module.http.internal.request.DefaultHttpRequester.innerProcess(DefaultHttpRequester.java:383)
at org.mule.module.http.internal.request.DefaultHttpRequester.processBlocking(DefaultHttpRequester.java:226)
Please advise.
The error indicates that the host name can not be found. That should be expected given that the host name is made up. You can find this error mentioned in this KB article: https://support.mulesoft.com/s/article/Error-sending-HTTP-request-with-java-util-NoSuchElementException
This error has nothing to do with HTTPS or the port used.
I have double checked that the host name is indeed not registered with nslookup:
c:\>nslookup xxx-yyy.com
Server: UnKnown
Address: 192.168.0.1
Non-authoritative answer:
Name: xxx-yyy.com
Address: 121.14.27.78

SSL redirect changes client IP address read from HTTPResponse

I am using Perfect Framework for my server side application running on an AWS EC2 instance. I am using the following code to get client IP address.
open static func someapi(request: HTTPRequest, _ response: HTTPResponse) {
var clientIP = request.remoteAddress.host }
This was working fine until I installed ssl certificate on my EC2 instance and start redirecting incoming traffic to port 443.
Now this code gives me the ip of my server, i think due to the redirect, Perfect somehow think request comes from itself.
Is there any other method to get client IP address? Or do i have to try something else?
Thanks!
For anyone struggling for the same problem, original client ip can be found in one of the header fields called "xForwardedFor" if there is a redirect, like the following:
var clientIP = request.remoteAddress.host
let forwardInfoResut = request.headers.filter { (item) -> Bool in
item.0 == HTTPRequestHeader.Name.xForwardedFor
}
if let forwardInfo = forwardInfoResut.first {
clientIP = forwardInfo.1
}
Hope this helps somebody, cheers!
Perhaps you should ask the people you are paying for support and whom manage the infrastructure how it works before asking us?
The convention, where an http connection is terminated elsewhere than the server is to inject an x-forwarded-for header. If there is already such a header, the intermediate server injects the client IP address at the front of the list.

Postfix: allow inbound relaying from only authenticated MTAs

I want to authenticate our customers' MTAs (Exchange for the most part, pointing to us as its smart host) to our relay server (Postfix 2.11.3, CentOS 6.6) and accept mail from only those authenticated MTAs.
I've looked into SASL, but as far as I can tell, its use case is for authenticating inbound MUAs or outbound MTAs.
How does one authenticate inbound MTAs using Postfix?
Thanks,
Nathan
EDIT:
From my main.cf:
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtpd_relay_restrictions = permit_sasl_authenticated, reject_unauth_destination
Other useful info:
postconf -a
cyrus
dovecot
vim /etc/dovecot/conf.d/10-auth.conf
auth_mechanisms = plain login
master.cf is virginal
SASL is the way to go. Postfix doesn't particularly care of it's an MUA or MTA connecting to it. If you use smtpd_sasl_auth_enable (along with smtpd_relay_restrictions = permit_sasl_authenticated and a proper SASL configuration), only authenticated connections will be able to use your server as a smarthost relay. Exchange supports this sort of thing, and it should be what you want.
I'm glad you could get it working with Dovecot - I couldn't! Fortunately, I wasn't married to Dovecot. I found this: http://initrd.org/wiki/SMTP_Relay which I followed and succeeded. Just having cert issues, but I'll take that up separately. Thanks again, Doug

NServiceBus Gateway public url

In my application I have a setup with NServiceBus Gateway on an endpoint and I was able to access it using the url http://localhost/{Endpoint name} from the same machine.
My question is what I have to do to access that endpoint from external machines using the public ip address or domain name.
For e.g. how can I access the gateway endpoint with url http://{My Public ip address}/{Endpoint name}
I found the answer by myself, what you have to do is simply change the channel address to the domain name you want
<GatewayConfig>
<Channels>
<Channel Address="http://{Your domain name}/{Endpoint name}/" ChannelType="Http" Default="true"/>
</Channels>
</GatewayConfig>