form1.frm

来自「此小程序可以根据IP地址」· FRM 代码 · 共 178 行

FRM
178
字号
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form Form1 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "IP归属查询"
   ClientHeight    =   3765
   ClientLeft      =   45
   ClientTop       =   330
   ClientWidth     =   6450
   Icon            =   "Form1.frx":0000
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   ScaleHeight     =   3765
   ScaleWidth      =   6450
   StartUpPosition =   3  '窗口缺省
   Begin InetCtlsObjects.Inet Inet1 
      Left            =   120
      Top             =   1680
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
   Begin VB.Frame Frame1 
      Caption         =   "本地网络"
      Height          =   735
      Left            =   120
      TabIndex        =   6
      Top             =   2880
      Width           =   6255
      Begin VB.Label Labar 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         ForeColor       =   &H00FF0000&
         Height          =   180
         Left            =   3600
         TabIndex        =   8
         Top             =   360
         Width           =   90
      End
      Begin VB.Label LabIP 
         AutoSize        =   -1  'True
         BackStyle       =   0  'Transparent
         ForeColor       =   &H000000FF&
         Height          =   180
         Left            =   1920
         TabIndex        =   7
         Top             =   360
         Width           =   90
      End
   End
   Begin MSWinsockLib.Winsock WinIP 
      Left            =   360
      Top             =   2400
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.CommandButton Command2 
      Caption         =   "IP查询地址"
      Height          =   495
      Left            =   3600
      TabIndex        =   5
      Top             =   1920
      Width           =   1455
   End
   Begin VB.CommandButton Command1 
      Caption         =   "网址转换成IP"
      Height          =   495
      Left            =   1800
      Style           =   1  'Graphical
      TabIndex        =   4
      Top             =   1920
      Width           =   1335
   End
   Begin VB.TextBox Text2 
      ForeColor       =   &H00FF0000&
      Height          =   375
      Left            =   2040
      Locked          =   -1  'True
      TabIndex        =   3
      ToolTipText     =   "锁定内容,无法修改!"
      Top             =   1200
      Width           =   3135
   End
   Begin VB.TextBox Text1 
      ForeColor       =   &H000000FF&
      Height          =   375
      Left            =   2040
      TabIndex        =   1
      Top             =   720
      Width           =   3135
   End
   Begin VB.Label Label2 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "IP归属地:"
      Height          =   180
      Left            =   1080
      TabIndex        =   2
      Top             =   1290
      Width           =   900
   End
   Begin VB.Label Label1 
      AutoSize        =   -1  'True
      BackStyle       =   0  'Transparent
      Caption         =   "查询的IP/网址:"
      Height          =   180
      Left            =   720
      TabIndex        =   0
      Top             =   840
      Width           =   1350
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Command1_Click()
    If Mid(Trim(Text1.Text), 1, 3) = "www" Or Mid(Trim(Text1.Text), 1, 3) = "WWW" Then
        WinIP.RemoteHost = Trim(Text1.Text)
        WinIP.RemotePort = 80
        WinIP.Connect Text1.Text, 80
        Command1.Enabled = False
    Else
        MsgBox "请输入正确的网址!" & vbCrLf & "注意不要有http://", vbExclamation, "提示!"
    End If
End Sub
Public Function GetAddress(sip)
    On Error Resume Next
    If Len(sip) < 5 Then
        GetAddress = "IP错误!"
        Exit Function
    End If
    Dim Wry, IPType
    Set Wry = New IPCLS
    If Not Wry.IsIp(sip) Then
        GetAddress = "IP错误!"
        Exit Function
    End If
    IPType = Wry.QQWry(sip)
    GetAddress = Wry.Country & " " & Wry.LocalStr
End Function
Private Sub Command2_Click()
    Command2.Enabled = False
    Text2.Text = GetAddress(Trim(Text1))
    Command2.Enabled = True
End Sub
Private Sub Form_Load()
    Dim StrTmp As String, Tmp As Long
    SetButton Command2.hWnd, vbRed, DT_VCENTER
    StrTmp = Inet1.OpenURL("http://www.ip138.com/")
    Tmp = InStr(1, StrTmp, "您的IP地址是:")
    If Tmp > 0 Then
        LabIP.Caption = "IP:" & Mid(StrTmp, Tmp + 8, InStr(Tmp + 9, StrTmp, "</td>") - (Tmp + 8))
    Else
        StrTmp = Inet1.OpenURL("http://vbnet.mvps.org/resources/tools/getpublicip.shtml")
        Tmp = InStr(1, StrTmp, "var ip = '")
        If Tmp > 0 Then
            Text1.Text = Mid(StrTmp, Tmp + 10, InStr(Tmp + 11, StrTmp, "'") - (Tmp + 10))
            LabIP.Caption = "IP:" & Mid(StrTmp, Tmp + 10, InStr(Tmp + 11, StrTmp, "'") - (Tmp + 10))
            Call Command2_Click
            Labar.Caption = Text2.Text
        Else
            LabIP.Caption = "网络不通啊!"
        End If
    End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
  RemoveButton Command1.hWnd
End Sub
Private Sub WinIP_Connect()
    Text1.Text = WinIP.RemoteHostIP
    WinIP.Close
    Command2.Enabled = True
End Sub

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?