📄 frmnet.frm
字号:
VERSION 5.00
Begin VB.Form frmNet
Caption = "网络编程"
ClientHeight = 3810
ClientLeft = 60
ClientTop = 345
ClientWidth = 6345
LinkTopic = "Form1"
ScaleHeight = 3810
ScaleWidth = 6345
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtHostName
Height = 375
Left = 2760
TabIndex = 4
Top = 720
Width = 1815
End
Begin VB.CommandButton cmdLocalName
Caption = "本地主机名"
Height = 375
Left = 240
TabIndex = 3
Top = 2640
Width = 1455
End
Begin VB.CommandButton cmdIP
Caption = "根据主机名获得IP地址"
Height = 375
Left = 1800
TabIndex = 2
Top = 2640
Width = 2055
End
Begin VB.TextBox txtIp
Height = 375
Left = 2760
TabIndex = 1
Top = 1680
Width = 1815
End
Begin VB.CommandButton cmdName
Caption = "根据IP地址获取主机名"
Height = 375
Left = 3960
TabIndex = 0
Top = 2640
Width = 2055
End
Begin VB.Label Label1
Caption = "主机名:"
Height = 375
Left = 1800
TabIndex = 6
Top = 720
Width = 735
End
Begin VB.Label Label2
Caption = "IP地址:"
Height = 255
Left = 1800
TabIndex = 5
Top = 1680
Width = 735
End
End
Attribute VB_Name = "frmNet"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim HostName As String * 256
Dim HostIP As String
Private Sub cmdLocalName_Click()
Dim iState As Integer
'初始化WinSock API函数库
iState = WinSockInit()
txtHostName.Text = GetLocalHostName()
'结束对WinSock API函数的调用,释放资源
WSACleanup
End Sub
Private Sub cmdIP_Click()
Dim iState As Integer
Dim sName As String
iState = WinSockInit()
sName = Trim$(txtHostName.Text)
txtIp.Text = Trim$(GetIPByName(sName))
WSACleanup
End Sub
Private Sub cmdName_Click()
Dim iState As Integer
Dim sIp As String
iState = WinSockInit()
sIp = Trim$(txtIp.Text)
txtHostName.Text = Trim$(GetNameByIp(sIp + vbNullChar))
WSACleanup
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -