How to decrypt or decode weird local IP - ip

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.

Related

How to get IP Address using Qt Framework

I want to get the IP Address and the country in which it belongs using Qt please help me with examples. thank you for your time.
I tried this code
foreach (const QHostAddress &address, QNetworkInterface::allAddresses()) {
if (address.protocol() == QAbstractSocket::IPv6Protocol && address != QHostAddress(QHostAddress::LocalHost)) {
qDebug() << address.toString();
}
}
but it did not work, i want to get the IP like the one witch gives the website http://whatismyipaddress.com/fr/mon-ip it gives the IP Address and the country in witch it belogns.
Thank you so much for your time.

how to get User IP address in asp.net?

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.

Find broken images in page & image replace by another image

Hi I am using selenium webdriver 2.25.0 & faceing the some serious issues,
how to find broken images in a page using Selenium Webdriver
How to find the image is replace by another image having same name (This is also bug) using webdriver.
Thanks in advance for your value-able suggestions.
The accepted answer requires that you use a proxy with an extra call to each image to determine if the images are broken or not.
Fortunately, there is another way you can do this using only javascript (I'm using Ruby, but you can use the same code in any executeScript method across the WebDriver bindings):
images = #driver.find_elements(:tag_name => "img")
broken_images = images.reject do |image|
#driver.execute_script("return arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0", image)
end
# broken_images now has an array of any images on the page with broken links
# and we want to ensure that it doesn't have any items
assert broken_images.empty?
To your other question, I would recommend just taking a screenshot of the page and having a human manually verify the resulting screenshot has the correct images. Computers can do the automation work, but humans do have to check and verify its results from time to time :)
The next lines are not optimized, but they could find broken images:
List<WebElement> imagesList = _driver.findElements(By.tagName("img"));
for (WebElement image : imagesList)
{
HttpResponse response = new DefaultHttpClient().execute(new HttpGet(image.getAttribute("src");));
if (response.getStatusLine().getStatusCode() != 200)
// Do whatever you want with broken images
}
Regarding your second issue, I think I didn't understand it correctly. Could you explain it with more detail?
Based on the other answers, the code that eventually worked for me in an angular / protractor / webdriverjs setting is:
it('should find all images', function () {
var allImgElts = element.all(by.tagName('img'));
browser.executeAsyncScript(function (callback) {
var imgs = document.getElementsByTagName('img'),
loaded = 0;
for (var i = 0; i < imgs.length; i++) {
if (imgs[i].naturalWidth > 0) {
loaded = loaded + 1;
};
};
callback(loaded);
}).then(function (loadedImagesCount) {
expect(loadedImagesCount).toBe(allImgElts.count());
});
});
The webdriver code counts the number of img elements, and the function executed within the browser context counts the number of successfully loaded elements. These numbers should be the same.

Why is this app blocking?

I just tried some code from the internet and ran it, but it blocked my emulator. The code is:
public void getcontents()
{
HttpConnection c = null;
InputStream is = null;
StringBuffer sb = new StringBuffer();
try
{
c = (HttpConnection)Connector.open("http://www.java-samples.com",Connector.READ_WRITE, true);
c.setRequestMethod(HttpConnection.GET); //default
is = c.openInputStream(); // transition to connected!
int ch = 0;
for(int ccnt=0; ccnt < 150; ccnt++) { // get the title.
ch = is.read();
if (ch == -1){
break;
}
sb.append((char)ch);
}
}
catch (IOException x){
x.printStackTrace();
}
finally{
try{
is.close();
c.close();
} catch (IOException x){
x.printStackTrace();
}
}
System.out.println(sb.toString());
}
I called the function with an OK command.
The emulator got blocked until I killed the process.
How do I solve this?
Try stepping through the code in the debugger. Or at the very least add some log statements. My guess is that the stream is waiting on data from the HTTP connection and isn't getting flushed but I haven't ran the code to verify that assertion.
The only loop I can see in your code is the for loop, which is finite (no more that 150 iterations), so that would not make the code execute indefinitely.
What I would suggest is place a number of debug output statements (output to a console or even dialog box alerts) at various points through the code. This will help you work out which line of code is causing the problem. For instance, if you put a line before and after the for loop and, when executing, only the first one is displayed, you know your problem is somewhere within the loop. You can then narrow it down by putting debug lines within the loop (including the loop number) to find out which line exactly is causing your problem.
Try checking the response code before attempting to read the response body from the server. This will either confirm the connection succeeds or print out the error response. Place the following after the call to Connector.open() :
if (c.getResponseCode() != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + c.getResponseCode());
} else {
System.out.println("**Debug** : HTTP_OK received, connection established");
}
If running the code then gives no output of either the exception or the HTTP confirmation then you are likely blocking on the connection attempt (check your emulator's connectivity to the internet). If you do get the HTTP_OK then you are likely blocking on the server's HTTP response, or lack thereof. Posting a comment with your results would be a good idea.

How can i get IP address in worklight?

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);
});

Resources