刚才问错了,应该是怎样用javascript获取本机ip地址?

wincommander 2002-04-28 06:48:14
牛人请回答,谢谢
...全文
72 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiushuiwuhen 2002-04-29
  • 打赏
  • 举报
回复
<object id=winsock1 classid=clsid:248DD896-BB45-11CF-9ABC-0080C7E7B78D onerror=alert("没有这个控件")></object>
<script>
alert(winsock1.localHostName)
alert(winsock1.localIP)
</script>
saucer 2002-04-28
  • 打赏
  • 举报
回复
如果你的ActiveX安全设置比较低的话,试试

<script language="vbscript">

TempFileName="c:\temp\Tempfile.txt"
TempBatchFileName="c:\temp\Tempfile.bat"

Const ForReading = 1, ForWriting = 2, ForAppending = 3
set oFileSystem = CreateObject("Scripting.FileSystemObject")
Set oFile = oFileSystem.CreateTextFile(TempBatchFileName, True)
oFile.WriteLine "cd\" & chr(13) & chr(10) & "ipconfig /all > " & TempFileName
oFile.Close
set oFile=nothing

set oShell=CreateObject("WScript.Shell")
iReturnValue=oShell.run(TempBatchFileName,1,true)

set oFile = oFileSystem.OpenTextFile(TempFileName, ForReading)
sIPString=oFile.ReadAll
msgbox sIPString
oFile.Close
set oFile=nothing

oFileSystem.DeleteFile TempBatchFileName,true
oFileSystem.DeleteFile TempFileName,true

set oFileSystem=nothing
set oShell = nothing

</script>
孟子E章 2002-04-28
  • 打赏
  • 举报
回复
NN4 (and NN3 I think but I haven't checked the code with it) allows
that by calling into Java:
var localhost = java.net.InetAddress.getLocalHost();
var hostname = localhost.getHostName();
var hostIP = localhost.getHostAddress();

alert('You are visiting from host ' + hostname
+ ' with ip address ' + hostIP);

The only way with IE to use Java is an applet but the above code
(transcribed into Java) run in an applet is reported to return
localhost
for the hostname respectively
127.0.0.1
for the ip address.

So all you can do for IE (and Opera and NN6) is to use server side
assists meaning a cgi script or php script dynmically returning the
REMOTE_ADDR cgi variable. I have set up such an assists at
http://www.csdn.net/jshelper/ipAddress.php
which returns a statement of the form
var ipAddress = '123.123.123.123;
so that a script can then access the variable
ipAddress
to read the value e.g.

<HTML>
<HEAD>
<SCRIPT SRC="http://www.csdn.net/jshelper/ipAddress.php">
</SCRIPT>
</HEAD>
<BODY>
<SCRIPT>
document.write(ipAddress)
</SCRIPT>
</BODY>
</HTML>
genuis 2002-04-28
  • 打赏
  • 举报
回复
同上
孟子E章 2002-04-28
  • 打赏
  • 举报
回复
IE不能实现,NS可以用java实现

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧