This is the label
<asp:Label ID="lblIp" runat="server"></asp:Label>
Here Code I used to get user IP address
string VisitorsIPAddr = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
VisitorsIPAddr = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
lblIp.Text = VisitorsIPAddr;
}
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
{
VisitorsIPAddr = HttpContext.Current.Request.UserHostAddress;
lblIp.Text = VisitorsIPAddr;
}
but Always I got the same result. That was 127.0.0.1 and always it goes to else if state.
further
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] did not give any result. It always give nothing
You are running the application at your own machine therefor you are the one sliding there, so you will always get 127.0.0.1 in the else if.
If you want to see another IP open the app and relevant port and get there with another machine.
Also the HTTP_X_FORWARDED_FOR is not always there (usually from normal web requests it will be but there are exceptions).
I think thats what Kundan Singh Chouhan tried to suggest, hope I am not wrong.
Related
I am Using Asp.net mvc5, I have table with fields like "id", and "server_IP" populated with n-numbers of server ip. And wants to display the status of each IP " success" or "timeout" depending upon ping.
I have used following;
Ping myPing = new Ping();
PingReply reply = myPing.Send("8.8.8.8", 1000);
if (reply != null)
{
ViewData["ip_stat"] = reply.Status;
}
I could not use this in my viewlist so that status of each servers can be shown as
Server Status
8.8.8.8 Success
192.168.10.10 timeout
192.168.100.1 sucess
REGARDS
ARUN SAHANI
Not sure if I have understood your question correctly, but going by the kind of output you are looking for and the way your are initializing the viewstate, I think you should concatenate the ip and the status while passing it into viewstate.
Something like this:
ViewData["ip_stat"] = reply.Address + " " + reply.Status;
Hope it helps.
Edited for the case where addresses are fetched from some table and needed to be passed to viewstate
// suppose this variable has the list of IP addresses from the table
var addresses = new List<string> {"8.8.8.8", "192.168.10.10", "192.168.10.8"}
var ipStatusDict = new Dictionary<string, string>();
//iterate over the list, fetch the status for each ip and add it within the dictionary
foreach(var ip in addresses)
{
var reply = new Ping().Send(ip, 1000);
if (reply != null)
{
ipStatusDict.Add(reply.Address, reply.Status);
}
}
ViewData["ip_stat"] = ipStatusDict;
I recently bought and RDp and everything went well, and i made a little script in .as (can't show it on here) which bounds to my local ip, e.g. 192.168.42.1, but when I tried the same on another rdp I got this: http://prntscr.com/6hywkm , a very odd IP, can anyone explain me how this comes and how to fix it(getting back a normal local ip 192.168.x.x)
Thanks.
seems like a IPv6 Address, so converting them to back to IPv4 ( like 127.0.0.1 ) is not possible all the time, so here is snippet in javascript which might help you out:
but keep in mind that its not always possible!
<script>
function parseIp6(str)
{
//init
var ar=new Array;
for(var i=0;i<8;i++)ar[i]=0;
//check for trivial IPs
if(str=="::")return ar;
//parse
var sar=str.split(':');
var slen=sar.length;
if(slen>8)slen=8;
var j=0;
for(var i=0;i<slen;i++){
//this is a "::", switch to end-run mode
if(i && sar[i]==""){j=9-slen+i;continue;}
ar[j]=parseInt("0x0"+sar[i]);
j++;
}
return ar;
}
function ipcnvfrom6(ip6)
{
var ip6=parseIp6(ip6);
var ip4=(ip6[6]>>8)+"."+(ip6[6]&0xff)+"."+(ip6[7]>>8)+"."+(ip6[7]&0xff);
return ip4;
}
alert(ipcnvfrom6("::C0A8:4A07"));
</script>
It's an IPv6 structure. Online convertor exists : http://www.subnetonline.com/pages/subnet-calculators/ipv4-to-ipv6-converter.php
but the conversion is not always possible.
How to check the given email (any valid email) address exists or not using ASP.NET?
You can't check if an email exists without actually sending an mail.
The only thing you can check is if the address is in a correct shape with regexes:
string email = txtemail.Text;
Regex regex = new Regex(#"^([\w\.\-]+)#([\w\-]+)((\.(\w){2,3})+)$");
Match match = regex.Match(email);
if (match.Success)
Response.Write(email + " is corrct");
else
Response.Write(email + " is incorrct");
you send invitation mail to user with encrypted key..
If user is verified you have to verified key and you have only verified email..
Here's a code solution that may work for you. This sample sends a message from address different from From: address specified in the message. This is useful when bounced messages should be processed and the developer wants to redirect bounced messages to another address.
http://www.afterlogic.com/mailbee-net/docs/MailBee.SmtpMail.Smtp.Send_overload_3.html
The full process is not so simple.
Its required a full communication with the email server and ask him if this email exist or not.
I know a vendor that give a dll that make all this communication and check if the email exist or not on the server, the aspNetMX at http://www.advancedintellect.com/product.aspx?mx
First you need to import this namespace:
using System.Text.RegularExpressions;
private bool ValidateEmail(string email)
{
Regex regex = new Regex(#"^([\w\.\-]+)#([\w\-]+)((\.(\w){2,3})+)$");
Match match = regex.Match(email);
if (match.Success)
return true;
else
return false;
}
Visit Here to full source code.
Answers on here and various other sites are often full of warnings not to trust HTTP Referrer headers because they are 'so easily' spoofed or faked.
Before I go any further - no, I'm not up to no good - but I do want to run some referrer-dependant tests.
Whilst I don't doubt that the warnings about fake referrers are true, I can't really find much detailed info on how they can be manipulated. Even the Wikipedia article only talks about it in general terms.
I'm about to play with the RefControl addin for FireFox.
Programatically (in ASP.NET specifically) the UrlReferrer is a read-only property, so I don't see how I can fire off requests with fake referrer data if I can't set it? Do I really have to do it manually?
How would I use ASP.NET to send a request to my site with a user-supplied variable to populate the referrer header?
EDIT : As per my comment below, I ideally want to take an incoming request, manupulate the referrer data and then pass the request on to another page, intact. If I can make it appear intact by building a new one from scratch and copying the original properties, then that is fine too.
I don't know if this exactly what you want, but in general, you should be able to spoof the value of the UrlReferer property (even if it's read-only) in HttpContext.Current.Request by using a bit of reflection.
For example:
FieldInfo fi = HttpContext.Current.Request.GetType().GetField("_referrer", BindingFlags.NonPublic | BindingFlags.Instance);
string initialReferer = HttpContext.Current.Request.UrlReferrer.ToString();
if (fi != null)
fi.SetValue(HttpContext.Current.Request, new Uri("http://example.com"));
string fakedReferer = HttpContext.Current.Request.UrlReferrer.ToString();
On VS; these are the values before and after changing the UrlReferrer:
initialReferer
"http://localhost/Test/Default.aspx"
fakedReferer
"http://example.com/"
If you open the System.Web assembly using ILSpy you'll notice that the UrlReferrer property looks something like this:
public Uri UrlReferrer
{
get
{
if (this._referrer == null && this._wr != null)
{
string knownRequestHeader = this._wr.GetKnownRequestHeader(36);
if (!string.IsNullOrEmpty(knownRequestHeader))
{
try
{
if (knownRequestHeader.IndexOf("://", StringComparison.Ordinal) >= 0)
{
this._referrer = new Uri(knownRequestHeader);
}
else
{
this._referrer = new Uri(this.Url, knownRequestHeader);
}
}
catch (HttpException)
{
this._referrer = null;
}
}
}
return this._referrer;
}
}
This likely isn't going to get you what you want. But you can edit the Referror of an HttpWebRequest. I don't think there is a way of editing the referrer of your request in context.
using System.Net;
HttpWebRequest Req= (HttpWebRequest)System.Net.HttpWebRequest.Create("http://somewhere.com/");
Req.Referer = "http://www.fakesite.com";
When calling Response.Cookie.Add(new HttpCookie("MyCookie", "objValue")); where does the cookie saved? on Client Machine or Server Machine?
EDIT:
if saved in Client Machine, how can I read it from javascript then? I tried this kind of script.
function getCookie(c_name) {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
}
}
}
I cannot get the cookie that I saved from code behind. When I look into the document.cookie object, it is just an empty string.
Scenario:
On Page_Init() on code behind. I create a cookie using Response.Cookie.Add(new HttpCookie("MyCookie", "cookieValue"));.
On Client side, I'm trying to read the cookie saved from code behind on page load using the snippet above, but it returns undefined
As Wikipedia explains, cookies string values that are stored on the client.
They are sent to server with each HTTP request as Cookie: headers.
You can store arbitrary objects in the server using session state.
Client machine. I'm sure google could give you a good explanation, But I use it everyday, and experience is my source.
Cookies are always saved at Client Machine.