First of all this is not a duplicate. Overall my question is:
I have another application currently running on macOS and I want to cut (sever or close or stop) it tcp connection from terminal. The problem is I don't want to kill process 'cause this is a solution what I found in another answers. + I have an access to sudo and I know the PID.
What I did and it doesn't work:
lsof -i TCP:X | awk '/LISTEN/ {print $2}' | xargs kill -9
I tried to change X to particular value which I got from this command
sudo lsof -i -n -P | grep TCP
The second thing placed here https://www.scm.keele.ac.uk/staff/stan/2016/05/16/closing-sockets-without-killing-processes/
But from that line lldb -p $PID I got an error like this:
error: attach failed: attach failed (Not allowed to attach to process. Look in the console messages (Console.app), near the debugserver entries when the attached failed. The subsystem that denied the attach permission will likely have logged an informative message about why it was denied.)
Maybe I missed something or maybe I should find a special program for my purpose? The Windows I see have one -> https://www.nirsoft.net/utils/cports.html
I'm really curious about it 'cause all answers which I found suggests users to kill all process. But I don't want it.
Ok.. just try to learn code from here -> https://github.com/doug-leith/appFirewall
Thanks dude for providing minus feedback for me. But my answer is the only one on internet which lead to working firewall!
I have both TCPView and Tcpvcon on my Windows 10 machine and I wonder how to get all the information (port numbers, etc.) displayed in TCPView in the output of the Tcpvcon program? TCPView has the process name, PID, protocol, remote address, remote port, etc. in its output to the GUI. Tcpvcon, on the other hand, only contains the process name, protocol, remote and local address. I would like to have all information that can be read in the TCPView GUI in the command line output of Tcpvcon (especially the port numbers). Tcpvcon seems to have only the three switches -a -c -n but no matter how I combine them, I do not reach my goal. Can anyone help me?
Below is a sample output when I use all three switches. In TCPView I see much more information about the specified process.
I was also very surprised that tcpvcon does not show port numbers (maybe we should ask Mark R. to add them ;-)
BUT you could use
netstat -a -o -n
or with an admin shell even
netstat -a -o -n -b
switches meaning:
-a ... Displays all active TCP connections and the TCP and UDP ports
on which the computer is listening.
-o ... Displays active TCP connections and includes the process ID (PID)
for each connection.
-n ... Displays active TCP connections, however, addresses and port numbers
are expressed numerically and no attempt is made to determine names.
-b ... Displays the executable involved in creating each connection or
listening port. (Note that this option can be time-consuming and
will fail unless you have sufficient permissions.)
To get all available switches just use netstat -? (there are other interesting ones) or https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/netstat
swobi
Up until the 2011 release of TCPVCON, it used to show port info.
The newer versions don't any more.
If you could get your hand on version 2.54, you would be able to get port info.
Tested with tcpvcon-v2.34 (I couldn't find 2.54) and it shows the ports but it doesn't show the process, all conections appear as from System. Also TCPV6 and UDPV6 are missing.
This is an example:
C:\WINDOWS\system32>"C:\My Program Files\TCPView-v4.13\tcpvcon-v2.34.exe" -a -c
TCP,System,-1,LISTENING,WXP-OR7507156:epmap,WXP-OR7507156:0
TCP,System,-1,LISTENING,WXP-OR7507156:microsoft-ds,WXP-OR7507156:0
TCP,System,-1,LISTENING,WXP-OR7507156:sms-rcinfo,WXP-OR7507156:0
TCP,System,-1,LISTENING,WXP-OR7507156:5040,WXP-OR7507156:0
TCP,System,-1,LISTENING,WXP-OR7507156:wsd,WXP-OR7507156:0
..
UDP,System,-1,,192.168.56.1:137,*:*
UDP,System,-1,,192.168.56.1:138,*:*
UDP,System,-1,,192.168.56.1:2177,*:*
UDP,System,-1,,192.168.56.1:5353,*:*
EDIT:
I correct myself. ASB was right.
I just got TCPView v2.54 and it does indeed show the application, the ports and also TCPV6 and UDPV6.
So I confirm that the "good" version is v2.54.
Tcpvcon.exe -a -c
TCPView v2.54 - TCP/UDP endpoint viewer
Copyright (C) 1998-2009 Mark Russinovich
Sysinternals - www.sysinternals.com
TCP,dnscrypt-proxy.exe,4188,LISTENING,WXP-XXX:domain,WXP-XXX:0
TCP,[System Process],0,TIME_WAIT,WXP-XXX:domain,localhost:62240
..
UDP,Teams.exe,12632,*,WXP-XXX:58950,*:*
TCPV6,svchost.exe,1232,LISTENING,wxp-XXX:135,wxp-XXX:0
..
UDPV6,svchost.exe,19712,*,wxp-XXX:50836,*:*
UDPV6,System,4,*,wxp-XXX:56736,*:*
To display the port numbers (and the process names) you need the old v2.54 version of tcpvcon.exe
This SysinternalsSuite.zip Archive from the Wayback Machine contains this version:
https://web.archive.org/web/20100201154325/http://download.sysinternals.com/Files/SysinternalsSuite.zip
For fun, I want to type something in Bash that will connect to an IRC server and automatically respond to PING messages
For example, I have the following output from telnet
Connected to irc.example.com.
Escape character is '^]'.
PING :12341234
If I pipe this to grep and then sed, I can easily turn this output into PONG :12341234, but how do I send it back to the standard input stream of telnet?
Additionally, I'd like to still being to manually send input using the keyboard
What you're trying to do is known as an "echo server". It is fairly easy to do with netcat and it's variants (nc or netcat, ncat, etc.).
For example:
ncat -l 2000 --keep-open --exec "/bin/cat"
In another shell
telnet localhost 2000
Whatever you send will be replied by ncat.
is there any way to control an already running VLC player on ubuntu.
For example, i am trying to start a vlc video full screen with a default audio.
and then control the volume and other features through netcat or some other command remotely. is it possible?
The script player control from exic's answer is just a wrapper for some dbus commands.
To use them without the script, try the following:
dbus-send --type=method_call --dest=org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
The last PlayPause can be replaced with, e.g., Play, Pause, Previous, Next.
If you have qdbus installed, it can be used as an alternative to dbus-send:
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause
A list of all available calls can be obtained by leaving out the last argument:
qdbus org.mpris.MediaPlayer2.vlc /org/mpris/MediaPlayer2
Have you looked at the rc (remote control) interface ? It controls a VLC process via a Unix Domain Socket. See here and here for more info.
If you enable the HTTP remote interface on VLC, you can control VLC remotely with a web browser, or even an app on your phone.
With the HTTP interface enabled, you can also use wget or curl commands to send commands.
For example, enable VLC's HTTP interface (default port: 8080) with "password" for a password. Then you can issue curl commands, either remotely or locally:
Curl Prefix
For brevity I will show the first part of the curl command here (the IP will most likely be your localhost, but the 8080 port is the default:
curl -s -o /dev/null -u :password http://192.168.1.11:8080
then combine with the actions:
To pause:
.../requests/status.xml?command=pl_pause
To play:
.../requests/status.xml?command=pl_play
To play a specific playlist entry number:
.../requests/status.xml?command=pl_play&id=22
To change volume:
.../requests/status.xml?command=volume&val=133
Other command info: https://wiki.videolan.org/VLC_HTTP_requests/
I'm controlling it remotely using dbus. VLC has implemented the MPRIS2 specification:
Control player (e. g. run player-control vlc toggle)
Get current status (with argument vlc)
I'm trying to write a server using netcat and bash. to recieve asynchronous packets, i'm using the command
netcat -lu 6791
How can I tell what host a packet came from? Is there a better tool i should be using then netcat (socat maybe?)
wireshark (GUI tool), tshark (text-based version of wireshark), and/or tcpdump (very similar to tshark, at least until you start messing with filtering out specific packets or searching for certain patterns or anything more complex) come immediately to mind...
#twalberg's suggestion,
netcat -vv -lu -p 6791 worked.