I am unable to get ip address of client using this following code. How can i modify this code? Please help me
This is .js code
function getIP(){
//return WL.Server.configuration["local.IPAddress"];
//alert(publicWorklightHostname);
var request = WL.Server.getClientRequest();alert('IP');
var ip = request.getHeader('x-client-ip');
alert(ip);
}
Try to use this
var request = WL.Server.getClientRequest();
var IPAddress = request.getHeader('x-forwarded-for');
Edit:
Also you can try this
WL.Device.getNetworkInfo(function (networkInfo) {
alert (networkInfo.ipAddress);
});
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 need to get the country of the customer who comes to the site.
I can use GeoIPHelper.GetCountryByIp("ip")to get Counry, but how can I get the ip address of the client that comes to the site?
Are you using Kentico EMS? If so then to get country of current contact:
var countryId = ContactManagementContext.CurrentContact.ContactCountryId;
var country = CoutryInfoProvider.GetCountryInfo(countryId);
Or
var currentLocation = GeoIPHelper.GetCurrentGeoLocation();
Which also contains country/state based on current request.
{%Ip%} in macro or var clientIp = CMS.Helpers.RequestContext.UserHostAddress
Or do you want to find out ip of existing customers?
That would be a sql query like
select Convert(xml,UserLastLogonInfo)
from COM_Customer Join CMS_User on CustomerUserID = UserID
it will give your xml like:
<info>
<agent></agent>
<ip></ip>
</info>
Looking at your code sample, I think you're in the code behind somewhere. This is possibly more of a general thing with ASP.NET. if that is the case, you can use HttpContext.Current.Request.UserHostAddress to get the IP of the current user.
There can be issues with this however if you're behind something like a load balancer. To combat that, you can try something like the following:
string userAddress = string.Empty;
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
{
userAddress = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
}
else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
{
userAddress = HttpContext.Current.Request.UserHostAddress;
}
var country = GeoIPHelper.GetCountryByIp(userAddress);
CMS.Helpers.RequestContext also works (as Shof says) but again, make sure to cater for any load balancer issues. To be honest, I've always fallen back to just using the HttpContext method from pre-Kentico habit.
GeoLocation currentGeoLocation = GeoIPHelper.GetCurrentGeoLocation();
if (currentGeoLocation != null)
{
var countryAndState = ValidationHelper.GetString(currentGeoLocation.CountryName, "");
var ipCountryCode = ValidationHelper.GetString(currentGeoLocation.CountryCode, "");
var ipRegion = ValidationHelper.GetString(currentGeoLocation.RegionName, "");
var ipCity = ValidationHelper.GetString(currentGeoLocation.City, "");
}
or macro
{% AnalyticsContext.CurrentGeoLocation.Country.CountryName%}
{% AnalyticsContext.CurrentGeoLocation.State%}
{% AnalyticsContext.CurrentGeoLocation.City%}
{% AnalyticsContext.CurrentGeoLocation.Postalcode%}
The client method DisplayMessage is not executing everytime. I need to display a stream of message. But when I put debugger in the client code, it executes everytime.Here is my client code.
chat.client.displayMessage = function (data) {
// Html encode display data
debugger;
var encodedData = $('<div />').text(data.GPSPosition).html();
var data = encodedData.split("\n");
var varlat = data[0].replace("Latitude:","").trim();
var varlong = data[1].replace("Longitude:", "").trim();
ShowInGoogleMap(varlat, varlong);
};
how can i display a stream of messages? Why it is only working with debugger?
Here is my server code. I am calling client method from a class outside the hub class.
IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<AzureGuidanceEventHubReceiver>();
hubContext.Clients.All.DisplayMessage(newData);
I think you have an issue in your code because your method parameter has the same name as a local variable (data). Modify the name of your local variable and it should be ok. In debug mode, the value of data is not overwritten.
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.
I'm sending a request to a server when a button is clicked:
private function submitButtonClicked():void
{
var variables:URLVariables = new URLVariables();
variables.table = tableInput.text;
var u:URLRequest=new URLRequest("http://sasajkl");
u.data = variables;
u.method = URLRequestMethod.POST;
var loader:URLLoader=new URLLoader();
loader.addEventListener(Event.COMPLETE,preparingCompleted);
loader.load(u);
}
The response from the server is actually a URL address, so my event handler is:
private function preparingCompleted(event:Event):void
{
var request:URLRequest=new URLRequest(event.target.data);
navigateToURL(request);
}
It used to work in the past, but now due to http://code.google.com/p/chromium/issues/detail?id=277210, it's not working anymore in Chrome. I tried to use fileReference.download(request,"Report.xls"), but then I get an error message because the function is not called as a response to a user action (such as a button click).
Does anyone have any idea how I can access the file from the URL address I get from the server?
Thanks.
From your own resource link, this is the work around:
ExternalInterface.call("window.open",url);