Wanted to use netcat (nc) on MS Windows.
What is NetCat ?
netcat is a computer networking utility for reading from and writing to network connections using TCP or UDP. The command is designed to be a dependable back-end that can be used directly or easily driven by other programs and scripts.
Function: Arbitrary TCP and UDP connections and listens.
Unfortunately, Anti-Virus (AV ) tools routinely block its use.
A sufficient workaround is to download the source code and recompile the source code and generate a new executable.
Here is a sample compilation code for Microsoft Visual Studio.Net.
setlocal set "_compilerFolder=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\Hostx86\x86\" set "_compilerBinary=cl.exe" set "_sourceCodeFolder=." set "_app=nc" set "_base=netcat" set "_option=getopt" set "_exec=doexec" set "_sourceCodeFile_01=%_base%.c" set "_sourceCodeFile_02=%_option%.c" set "_sourceCodeFile_03=%_exec%.c" set "_outputFile=%_app%.exe" set "_DEBUG=/DEBUG:FULL /Z7" rem set "_DEBUG=/Z7" set "_compilerFlag=%_DEBUG%" "%_compilerFolder%\%_compilerBinary%" %_sourceCodeFolder%\%_sourceCodeFile_01% ^ %_sourceCodeFolder%\%_sourceCodeFile_02% ^ %_sourceCodeFolder%\%_sourceCodeFile_03% ^ /Fe:%_outputFile% %_compilerFlag% endlocal
Source Code Changes
Error – 1 – fatal error C1083: Cannot open include file: ‘sys/time.h’: No such file or directory
- The error is due to the location of the sys/time.h file in Microsoft Visual Studio
- The code is looking for it it as sys/time.h.
- Whereas it is not in sys subfolder
- Add #define WIN32
- Defining WIN32 will have compiler look for time.h in the root header folder and not under under the sys sub-folder