How to get the port associated to an IP address with VBA (1 Viewer)

nector

Member
Local time
Tomorrow, 01:55
Joined
Jan 21, 2020
Messages
368
Is there a way to get the port number associated to the local IP address with VBA, I know I can get the IP address with the VBA below:

Code:
Public Function getMyIP()
    'Related Reference - Microsoft WMI Scripting V1.2 Library (wbemdisp.TLB)
    'Define Variable Data Types
    Dim objWMI As Object
    Dim objQuery As Object
    Dim objQueryItem As Object
    Dim vIpAddress
    
    'Create WMI Object
    Set objWMI = GetObject("winmgmts:\\.\root\cimv2")
    
    'Query WMI
    Set objQuery = objWMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
    
    'Loop Thru all assigned IP Addresses
    For Each objQueryItem In objQuery
        Debug.Print vbCrLf & "All Assigned IP Addresses"
        For Each vIpAddress In objQueryItem.IpAddress
            Debug.Print "User IP - " & vIpAddress
        Next
    Next
    
End Function
 

cheekybuddha

AWF VIP
Local time
Today, 23:55
Joined
Jul 21, 2014
Messages
2,280
Hi,

Your question doesn't really make sense.

An IP address will point to a machine on the network. It will have all ports available, unless blocked by a firewall.

Servers like MySQL, SQLServer, web servers, mail servers on those machines will 'listen' on various ports, typically 3306, 1433, 80 and 443, 25, 465, 993.

Are you trying to find all open ports for an IP address? Or something else ... ?
 

Users who are viewing this thread

Top Bottom