如何使用VB.NET获取计算机地址? [英] How can I get computer addresses using VB.NET?

查看:83
本文介绍了如何使用VB.NET获取计算机地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我想问一下,每次按下一步按钮时,如何获取将使用我的排队系统的计算机的IP地址。语音合成器应该说现在服务号#ticket_number#,请继续计数#computer's_name#。下面是我从互联网上获得的一堆代码。有没有可能的方法我可以修改代码以我想要的方式工作?感谢您的帮助!



我的尝试:



Hi! I want to ask how I can get the ip addresses of the computers that will use my queuing system every time they press the "next" button. The speech synthesizer should say "now serving number #ticket_number#, please proceed to counter #computer's_name#". Below is a bunch of code I got from the internet. Is there any possible way I can modify that code to work the way I want it to? Thanks for the help!

What I have tried:

Dim strHostName As String

Dim strIPAddress As String



strHostName = System.Net.Dns.GetHostName()

strIPAddress = System.Net.Dns.GetHostByName(strHostName).AddressList(0).ToString()


MessageBox.Show("Host Name: " & strHostName & "; IP Address: " & strIPAddress)

推荐答案

GetHostName返回运行代码的计算机的名称,以及您从中获得的地址列表也将用于同一台计算机 - 这意味着您获得的IP地址将始终是本地LAN IP地址,可能是192.168.xx,因为大多数LAN段默认为此。您无法直接获取互联网IP地址,因为它们是您的用户与互联网联系的地址 - 通常是路由器 - 并且未分配给单个计算机。

您可以获得Internet IP PC正在使用的地址 - 使用基于IP的地理位置 - 以及为什么它几乎没用。 [ ^ ]显示代码 - 在miond中的bvut,它不是特定计算机所特有的,而是由使用该路由器的所有计算机共享。



如果您想通过在主机上运行代码来获取客户端详细信息,那就不同了 - 这将取决于客户端与服务器的确切连接方式。例如,基于套接字的方法与网站/网络服务方法有很大不同。
GetHostName returns the name of the computer running the code, and the address list you get from that will also be for the same computer - which means that the IP address you get will always be the Local LAN IP address, which is probably going to be 192.168.x.x because most LAN segments default to this. You cannot get an internet IP address directly because they are the addresses to your users point of contact with the internet - usually the router - and are not assigned to an individual computer.
You can get the Internet IP address that a PC is using - Using IP based Geolocation - and why it's pretty much useless.[^] shows the code - bvut bear in miond that it isn't unique to a specific computer, but is shared by all the computers using that router.

If you want to get the client details by running code on the host computer, then that is different - and will depend on exactly how your clients are connected to the server. A Sockets based approach would be very different from a website / web service approach for example.


这篇关于如何使用VB.NET获取计算机地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆