Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement process Port View in batch processing

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article shares with you about how batch processing implements process port viewing. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Just save the following code as port_bat.bat and run it.

The code is as follows:

@ echo off

Color a

Title XP Port-process query

Setlocal enabledelayedexpansion

Echo ╔-- ╗

The port opened locally by echo and the processes that use it

Echo ╚-- ╝

Echo--

Echo port number process name

ECHO TCP protocol:

Use the netstat command to find out the port that uses the TCP protocol to communicate, and divide the result

:: pass the second parameter (IP plus port) to% I and the fifth parameter (PID number) to% j

For / F "usebackq skip=4 tokens=2,5"% I in (`"netstat-ano-p TCP"`) do (

Call: Assoc% I TCP% j

Echo! TCP_Port!! TCP_Proc_Name!

)

ECHO UDP protocol:

For / F "usebackq skip=4 tokens=2,4"% I in (`"netstat-ano-p UDP"`) do (

Call: Assoc% I UDP% j

Echo! UDP_Port!! UDP_Proc_Name!

)

Echo press any key to exit

Pause > nul

: Assoc

:: split% 1 (the first parameter) and pass the second parameter to% e. In this program,% 1 is the% I above (in the form: IP: Port number)

For / F "tokens=2 delims=:" e in ("1") do (

Set 2_Port=%%e

)

:: query the process whose PID is equal to% 3 (the third parameter) and pass the result to the variable? _ Proc_Name,? Stands for UDP or TCP

For / F "skip=2 usebackq delims=, tokens=1" an in (`"Tasklist / FI" PID eq 3 "/ FO CSV"`) do (

::% ~ a means to remove the quotation marks outside% a, because the result of the above command is enclosed in parentheses.

Set 2_Proc_Name=%%~a

)

Thank you for reading! This is the end of this article on "how to implement process port viewing in batch processing". I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it out for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report