⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.frm

📁 呵呵,用最简单的办法,取得自己的所在的公网IP
💻 FRM
字号:
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 
   Caption         =   "Form1"
   ClientHeight    =   2535
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4815
   LinkTopic       =   "Form1"
   ScaleHeight     =   2535
   ScaleWidth      =   4815
   StartUpPosition =   2  '屏幕中心
   Begin InetCtlsObjects.Inet Inet1 
      Left            =   3840
      Top             =   120
      _ExtentX        =   1005
      _ExtentY        =   1005
      _Version        =   393216
   End
   Begin MSWinsockLib.Winsock Winsock1 
      Left            =   240
      Top             =   120
      _ExtentX        =   741
      _ExtentY        =   741
      _Version        =   393216
   End
   Begin VB.CommandButton Command1 
      Caption         =   "获得IP"
      Height          =   615
      Left            =   1920
      TabIndex        =   0
      Top             =   120
      Width           =   1095
   End
   Begin VB.Label Label2 
      Caption         =   "Label2"
      Height          =   495
      Left            =   120
      TabIndex        =   2
      Top             =   1440
      Width           =   4335
   End
   Begin VB.Label Label1 
      Caption         =   "Label1"
      Height          =   375
      Left            =   120
      TabIndex        =   1
      Top             =   960
      Width           =   4215
   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()
Dim ip_all As String
'用Winsock 一句话得IP,可惜这样通常是内网的IP。
ip_all = Winsock1.LocalIP
ip_3 = Val(Left$(ip_all, 3))
'判断 IP是否在内网
If ip_3 = 192 Then
Label1.Caption = "您的机器处在内网,IP地址为" & Winsock1.LocalIP
End If
'进入 www.ip138.com 取得代码,再过滤过IP地址 ,我这样拿到外网IP的,呵呵
ip_gw = Inet1.OpenURL("http://www.apnic.net/")
ip_gw = Mid$(ip_gw, InStr(ip_gw, "Your IP:") + 41, 25)
'ip_gw = Replace(ip_gw, "您的IP地址是", "")
'ip_gw = Replace(ip_gw, ":", "")
'ip_gw = Replace(ip_gw, "'", "")
'ip_gw = Replace(ip_gw, ":", "")
ip_gw = Replace(ip_gw, "<", "")
ip_gw = Replace(ip_gw, ">", "")
ip_gw = Replace(ip_gw, "/", "")
ip_gw = Replace(ip_gw, "a", "")
ip_gw = Replace(ip_gw, "t", "")
ip_gw = Replace(ip_gw, "s", "")
ip_gw = Replace(ip_gw, "t", "")
ip_gw = Replace(ip_gw, "p", "")
ip_gw = Replace(ip_gw, "d", "")
ip_gw = Replace(ip_gw, "n", "")
Label2.Caption = "公网IP为:" & ip_gw

End Sub

⌨️ 快捷键说明

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