Jump to content
Sign in to follow this  
VixinG

Netstat and port display

Recommended Posts

VixinG

Netstat:

Protokół      Adres lokalny                Obcy adres                     Stan                          PID
TCP            192.168.1.250:3509    193.120.199.13:80         USTANOWIONO         3692
[Skype.exe]
TCP            192.168.1.250:3519    157.55.130.145:40041   USTANOWIONO         3692
[Skype.exe]
TCP            192.168.1.250:3527    173.194.70.125:443       USTANOWIONO         2936

Code:

#include <Constants.au3>
    $netstat = Run(@ComSpec & " /c netstat -n -b", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    $out = StdoutRead($netstat)
$line = StringSplit($out,@LF)
For $i = 0 to UBound($line) - 1
  If StringInStr($line[$i],"192.168.1.250:") Then
   $var = StringTrimLeft($line[$i], StringInStr($line[$i],"192") + 14)
   $port = StringLeft($var, 4)
   MsgBox(0,'Port','Used port: ' & $port)
  EndIf
Next

I don't know why it isn't working... It should find a line with 192.168.1.250: and with MsgBox pop-up the port, but it isn't.

Why? ;)


[indent=3][/indent]

Share this post


Link to post
Share on other sites
UEZ

Try this:

#include <Constants.au3>
$netstat = Run(@ComSpec & " /c netstat -n -b", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
Global $out
While 1
    $out &= StdoutRead($netstat)
    If @error Then ExitLoop
    Sleep(10)
WEnd
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $out = ' & $out & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console
$line = StringSplit($out,@LF)

For $i = 0 to UBound($line) - 1
  If StringInStr($line[$i],"192.168.1.250:") Then
   $var = StringTrimLeft($line[$i], StringInStr($line[$i],"192") + 14)
   $port = StringLeft($var, 4)
   MsgBox(0,'Port','Used port: ' & $port)
  EndIf
Next

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
VixinG

Thanks! ;)

regards


[indent=3][/indent]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×