I am Useing HttpWebRequest for communications. It is possible to get website ip address(dedicated ip) not server ip. when i use Context.Request.ServerVariable("Remote_Addr") it return only server ip. But I need website ip address.
For Example
There are 3 client's website send httpwebrequest to my site. Each have dedicated ip address.
My Website Receive that Request and perform some work and then response.
Example Coding Client Send HttpWebRequest:
Dim uri As New Uri("http://www.somewebsite.com/somepage.ashx?username=client1&password=123456")
If (uri.Scheme = uri.UriSchemeHttp) Then
Dim wrequest As HttpWebRequest = HttpWebRequest.Create(uri)
wrequest.Method = WebRequestMethods.Http.Get
Dim wresponse As HttpWebResponse = wrequest.GetResponse()
Dim reader As New StreamReader(wresponse.GetResponseStream())
Dim tmp As String = reader.ReadToEnd()
wresponse.Close()
End If
Example Coding For HttpHandler:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim remoteIP As String = context.Request.ServerVariables("REMOTE_ADDR")
If remoteIP = "client1ip" Then
Dim ref As String = Trim(context.Request.QueryString("username"))
Dim number As String = Trim(context.Request.QueryString("password"))
'do some work
Else
context.Response.Write("Access Denied")
End If
End Sub
This is my example coding. Here remoteIP return hosting provider server ip but i need website ip address.
it is possible to get website ip address using httpcontext in httphandler.
This should do what you're looking for. It will do a DNS lookup on the hostname of the website, which should give you the IP Address that it is listening on.
string dnsHostname = "yourwebsite.com";
IPAddress[] addresslist = Dns.GetHostAddresses(dnsHostname);
foreach (IPAddress theaddress in addresslist)
{
Console.WriteLine(theaddress.ToString());
}
You will likely only need the first result of the array.
Based on what you've said so far, the variables you're looking for are:
Request.UserHostAddress
Request.UserHostName
The issue you will be that you might not get a unique IP if they're using a proxy, but other than that, you should be able to get what you need from them.
After understanding your question more now...
I don't think you are going to be able to get the vistor this other website that is connecting to your site. Technically the only connection to your website is the website that is connecting to you, so unless they can pass the user's ip address, you will have no exposure to that
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.