重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
做exe程序获取本机IP地址用
为肥乡等地区用户提供了全套网页设计制作服务,及肥乡网站建设行业解决方案。主营业务为网站建设、成都网站制作、肥乡网站设计,以传统方式定制建设网站,并提供域名空间备案等一条龙服务,秉承以专业、用心的态度为用户提供真诚的服务。我们深信只要达到每一位用户的要求,就会得到认可,从而选择与我们长期合作。这样,我们也可以走得更远!
System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName()).AddressList
做web程序获取客户端的IP地址用
HttpContext.Current.Request.ServerVariables("REMOTE_ADDR"])
你最好可以换台电脑访问网址看获取IP地址状况。
如果你测试访问的时候,使用的是 localhost 进行访问的,那么服务器端获得的也就是127.0.0.1,因为localhost是一个环路地址,特殊的.如果你是通过你的ip地址进行访问的,那么获得的IP地址就会是正确的了. 要通过自己本地的IP进行访问,在控制面板的网络连接里找到本地连接,查看它的属性,并找到"详细信息"按钮,点击后弹出的对话框中IPV4地址就是本地地址.或打开命令行,输入 ipconfig /all 即可找到本地地址.在浏览器中通过这个IP地址访问,就不会是127.0.0.1了.
Dim IPAdress As System.Net.IPAddress
HostName = System.Net.Dns.GetHostName '获得本机的机器名
IPAdress = System.Net.Dns.GetHostByName(HostName).AddressList.GetValue(0) '获得本机的IP
Me.TextBox1.Text = HostName '本机机器名
Me.TextBox2.Text = IPAdress.ToString '本机的IP
我来说说...i试试看行不行。Option Explicit
Const SYNCHRONIZE = H100000
Const INFINITE = HFFFF
Const WAIT_OBJECT_0 = 0
Const WAIT_TIMEOUT = H102
Private Declare Function SendMessage Lib "User32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub cmdClear_Click()
txtIP.Text = ""
txtNumber.Text = ""
Open "C:\log.txt" For Output As #1
Close #1
txtOutPut.Text = ""
End Sub
Private Sub cmdPing_Click()
Dim ShellX As String
Dim lPid As Long
Dim lHnd As Long
Dim lRet As Long
Dim VarX As String
frmMain.MousePointer = 11
If txtIP.Text "" Then
DoEvents
ShellX = Shell("command.com /c ping -n " txtNumber.Text " " txtIP.Text " C:\log.txt", vbHide)
lPid = ShellX
If lPid 0 Then
lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
If lHnd 0 Then
lRet = WaitForSingleObject(lHnd, INFINITE)
CloseHandle (lHnd)
End If
Beep
frmMain.MousePointer = 0
Open "C:\log.txt" For Input As #1
txtOutPut.Text = Input(LOF(1), 1)
Close #1
End If
Else
frmMain.MousePointer = 0
VarX = MsgBox("You have not entered an ip address or the number of times you want to ping.", vbCritical, "Error has occured")
End If
End Sub
MsgBox(System.Net.Dns.GetHostEntry(System.Net.Dns.GetHostName).AddressList(0).ToString)这是vb2008里面的格式,这是显示自己的IP,不知你是想要获取哪些IP 呢
1.获取当前电脑名:System.Net.Dns.GetHostName()
2.根据电脑名取出全部IP地址:System.Net.Dns.Resolve(电脑名).AddressList
或者 System.Net.Dns.GetHostByName(电脑名).AddressList
3.根据IP地址取出电脑名:System.Net.Dns.Resolve(IP地址).HostName