
|
View Full Version : Ip Address in html document
-Edward- 10-10-2000, 11:45 AM hello, I know to to make an ip address show up in php and cgi but how do i make it appear in a simple html document? what code do i use to detect it?
i'm guessing id use javascript right?.
Learner 10-10-2000, 05:37 PM You would have to use a script in this case. That is because HTML 4.0 doesn't allow you to access IP addresses in itself !!!
Here is the code which will only work in Netscape with Java enabled. It will not work in IE. Paste it into the BODY of your HTML document.
Enjoy !!!
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
if ((navigator.appVersion.indexOf("4.") != -1) && (navigator.appName.indexOf("Netscape") != -1)){
ip = "" + java.net.InetAddress.getLocalHost().getHostAddress();
document.write("Your IP address is " + ip);
}
else {
document.write("IP Address only shown in Netscape with Java enabled!");
}
// End -->
</script>
~ Learner
Well, you could use Server Side Includes if your server supports it.
-Edward- 10-10-2000, 05:46 PM Thanks learner but i dunt have nutscape installed so i wouldsnt know if it worked :-(.
Learner 10-10-2000, 05:55 PM ... have any other lighter Mozilla based browser? The newer versions of such browsers may be javascript compatible. The code should work if run in such browsers.
You could easily download such browsers from http://www.download.com ... sizes can range between 2 MB to 4 MB only.
BTW, the reason that the above code doesn't work in IE 5.0 is that JScript (IE) has some inherent differences from JavaScript (Netscape).
But try the code on IE 5.5... i don't know if it has been upgraded to become more JavaScript compitable. Let me know if it works. I am yet to install IE 5.5.
Learner
-Edward- 10-10-2000, 06:01 PM I'm using i.e 5.1 on this machine but i will look around and thanks for the information.
Use SSI, because for those of us behind firewalls, you'll get an invalid ip.
Félix C.Courtemanche 10-10-2000, 11:08 PM SSI will not necessarily display the same IP as a javascript enabled web browser would (by the way). SSI, php, CGI, etc will display the ip that the browser sees (yours zor your proxy's ip) and javascript will display your true IP because it is ran locally and not remotely.
Learner 10-11-2000, 03:40 AM Originally posted by JTY
Use SSI, because for those of us behind firewalls, you'll get an invalid ip.
JTY... I didn't know this before.
1. Is this true for all firewalls?
2. Do firewalls block the IP? What makes it "INVALID" exactly? Is it a proxy IP that is *shared* by many users that makes it "INVALID".
Would like to learn more, because if I am not mistaken, all data packets transmitted need to have an IP, or else they would not travel via the net. I hope I am not wrong in my assumption.
Originally posted by Félix C.Courtemanche
SSI, php, CGI, etc will display the ip that the browser sees (yours or your proxy's ip) and javascript will display your true IP because it is ran locally and not remotely.
Felix... So even if a firewall is being run at the remote host's end, JavaScript would still display the actual IP being sent the data packets are being transmitted with, is that correct?
Learner
kunal 10-11-2000, 04:22 AM While we are on this topic, I have been trying to find a way to run cleint side code on the server side! basically what I mean is, make the cleint side code detect the wrong IP of a user. Any ideas?
[Edited by kunal on 10-11-2000 at 04:27 AM]
Learner,
How a firewall works is this : a genuinely useful firewall like ZoneAlarm can be configured to whatever way you like, but the best way (for a personal user anyway) is to allow 'outgoing' traffic (e.g. on HTTP, FTP and Telnet ports depending on the functions or operations you're performing). This outgoing traffic is not spoofed, nor is it necessary as 'crackers' (using the correct Net terms) have little use for outgoing traffic.
What crackers try to do is send some 'incoming' traffic to see what vulnerabilities are present on your computer. A firewall helps to screen this out by either closing down all the ports you aren't using, or spoofing the IP address to something like 127.0.0.1 (localhost), thus sending the traffic back.
You are correct in your assumption regarding packets, but recall they must be two-way so that communication between computers and servers can occur. It's not much use calling a cab when there's no road to your house at all.
What Felix meant is that JavaScript will detect the 'correct' local IP address (i.e. your own computer's) because it runs on your machine. However, JavaScript, being client side, can not possibly detect a remote server's IP - use tracert/ping/WHOIS/IP blocks instead. JavaScript will always be able to read your computer's correct IP because it looks directly at the appropriate network level and bypasses the firewall (which is more a 'gate' if you like - i.e. JScript goes direct to the boiler room without going outside).
Kunal,
The only way I can see that happening is to remotely trigger a script on the remote server which then in turn triggers the client side script on the server. However this is extremely tricky (if not downright impossible).
Learner 10-11-2000, 08:02 AM Originally posted by BC
You are correct in your assumption regarding packets, but recall they must be two-way so that communication between computers and servers can occur. It's not much use calling a cab when there's no road to your house at all.
Thanks for your informative post, BC.
Yes... the communication has to be two-way.
But you really got me laughing with your last analogic sentence above :D I really am amazed at the funny comments both you and Chicken regularly spoof out here :D Great fun really !!!!!!
Duster's comments are often equally notoriously funny. He too has a knack of making such comments at times !!!!!! :D And often his sarcastic comments have a lot of inherent wisdom, if one really understands what I am referring to !!!!!
All this is really welcome... adds fun to techy posts like these !!!!!!! :D I am recalling Felix's recent post where he made an equally sarcastic comment on Alabanza when a member asked what would happen to those who gamble on playing numbers !!!!! LOL !!!!!! :D
Learner
Learner, two things :
1. Analogies always helps to illustrate concepts, techie or non-techie - the more humorous the easier they're able to be understood and actually retained in memory (well, what little there is in your brain, anyway... And no, I wasn't implying anyone in particular. Uh hem. Well, maybe one or two idiots... ;))
2. Are you aware of a limit on the no. of images allowed per post? ;) Don't want you going overboard with the :D so that you can't even post! :stickout
Learner 10-11-2000, 08:19 AM Originally posted by BC
Analogies always helps to illustrate concepts, techie or non-techie - the more humorous the easier they're able to be understood and actually retained in memory...
Yup... very very true, BC !!!!!!
Well, enough said on this for now... let us have this thread continue on topic :)
Learner
Félix C.Courtemanche 10-11-2000, 02:00 PM However, Javascript will not always work, which makes server side stuff usefull.
To use the server-side detected IP from javascript you would have to:
make a server-side script that would _generate_ the javascript code and send in the IP as a variable.
Here is a little example to do that in PHP+javascript, but it can easily be modified for any other language.
<SCRIPT>
var ipaddress;
ipaddress = "<? echo getenv("REMOTE_ADDR") ?>";
document.write(ipaddress);
</SCRIPT>
Now, as you can see, the <? ... ?> par is the embeded PHP code compatible with any PHP installation. You can modify everything in this script, but you get the basic idea. Now, my suqestion is.... why would you want to use Javascript with a server-side generated IP???
:)
The reason I said the ip would be invalid, is for instance that our school uses private ips, which are then masqed and proxied by a Linux box.
Therefore the ip of a workstation could be 192.168.3.20 or in the case of at my house 192.168.1.10.
|