It can be broadly divided into two ways:
1. Call Nmap for port scanning
Msfconsole
Nmap-v-SV www.cstc.org.cn
Scan results (port opening and operational information for the target service operating system)
PORT State SERVICE VERSION
21/TCP Open FTP Microsoft ftpd
80/TCP Open http Apache tomcat/coyote JSP engine 1.1
135/tcp Open MSRPC Microsoft Windows RPC
139/tcp Open NETBIOS-SSN Microsoft Windows 98 NETBIOS-SSN
445/tcp Filtered Microsoft-ds
514/tcp Filtered Shell
1025/tcp Open MSRPC Microsoft Windows RPC
1026/tcp Open MSRPC Microsoft Windows RPC
1038/tcp Open MSRPC Microsoft Windows RPC
3306/tcp open MySQL MySQL 5.0.27-community-nt
3389/tcp Open Ms-wbt-server Microsoft Terminal Service
4444/tcp Filtered krb524
8009/tcp Open ajp13 Apache jserv (Protocol v1.3)
8090/TCP Open http Microsoft IIS httpd 6.0
Service Info:OSs:Windows, Windows 98; Cpe:cpe:/o:microsoft:windows, cpe:/o:microsoft:windows_98
2. Call the MSF module for port scanning
metasploit-Port Scan