获得在新的批处理文件的netstat -e一些信息 [英] Get some information from netstat -e in new batch file

查看:365
本文介绍了获得在新的批处理文件的netstat -e一些信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

海兰,我想创建批处理文件来显示约下载包和包上传用户信息。这个信息,我可以从命令netstat的-e'让我可以用'netstat的-e> log.txt的保存日志文件中此信息。
但我想,打开此新的批处理文件时,用户可以看到上传和下载软件包只资讯,而不是从这个命令的所有信息,这样的事情:

Hy, I want to create batch file to display to the user information about Downloaded packages and Uploaded packages. This info I can get from command 'netstat -e' and I can save this info in log file using 'netstat -e >log.txt'. But I want, when opening this new batch file, that user can see only info about Downloaded and Uploaded packages, not all info from this command, something like this:

下载的包:
-info从netstat中-e -

Downloaded packages: -info from netstat -e-

上传包:
-info从netstat中-e -

Uploaded packages: -info from netstat -e-

是,这是不可能削减从日志文件这些信息并把它放到批处理文件,当用户打开该批次?整个过程中,打开批处理文件后,会是这个样子:
与'netstat的-e> log.txt的' - 保存日志文件,
-getting需要的信息,
在批处理文件-put这个信息,
- 现在用户看到这些信息。

Are it's impossible to cut this info from a log file and put it into batch file when user open this batch? The whole process, after is opening batch file, would look something like this: -save log file with 'netstat -e >log.txt', -getting needed information, -put this info in batch file, -now user see this information.

方法来做这可以是任何东西,像使用CMD和VBS或其他。

Methods to do this can be anything, like using cmd and VBS or other.

推荐答案

刚管的netstat通过这样find命令的结果。

Just pipe the result of netstat through the find command like this

netstat -e | find "Bytes"

您仍可以重定向到一个这样的文本文件

you can still redirect to a textfile like this

netstat -e | find "Bytes" > text.txt

编辑:基于您的评论在这里更多的可能性。

based on your comment here more possibilities

没有需要一个单独的程序。
可以通过管道将2值与测试或批处理文件这样的评论。
对于在圆括号之间的文字/ F''执行该命令,并让有关分析结果。令牌= 2,3跳过第一个结果(字节),将两个人在一个独立的VAR

No need for a separate program. You can pipe the 2 values with comment to a test or batchfile like this. For /F with the text in parantheses between '' executes the command and lets For parse the result. Tokens=2,3 skips the first result (Bytes) and puts the two others in a separate var

for /F "tokens=2,3" %a in ('netstat -e ^| find "Bytes"') do echo received:%a sent:%b>log.txt

这给出的log.txt

this gives in log.txt

received:74546759 sent:8593498

或者你可以将值设置为环境变量,并用它在批处理像

or you can set the value to environment variables and use it in a batch like

for /F "tokens=2,3" %a in ('netstat -e ^| find "Bytes"') do set received=%a&set sent=%b

组给出然后

..
received=75230393
sent=8966725
..

也可以作为参数发送的值,以这样的一批

or you can send the values as a parameter to a batch like this

for /F "tokens=2,3" %a in ('netstat -e ^| find "Bytes"') do mybatch %a %b

这篇关于获得在新的批处理文件的netstat -e一些信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆