Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
B
bsc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexlab
bsc
Commits
fd78e572
Commit
fd78e572
authored
Oct 19, 2025
by
Kilo Code
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add continuous monitoring with periodic status logging
parent
63bf10d8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
75 additions
and
0 deletions
+75
-0
network_monitor.c
network_monitor.c
+75
-0
No files found.
network_monitor.c
View file @
fd78e572
...
@@ -24,6 +24,7 @@
...
@@ -24,6 +24,7 @@
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <tlhelp32.h>
#include <tlhelp32.h>
#include <psapi.h>
// #pragma comment(lib, "ws2_32.lib")
// #pragma comment(lib, "ws2_32.lib")
// #pragma comment(lib, "iphlpapi.lib")
// #pragma comment(lib, "iphlpapi.lib")
...
@@ -137,6 +138,7 @@ int main() {
...
@@ -137,6 +138,7 @@ int main() {
FILE
*
internal_log
=
fopen
(
internal_log_path
,
"a"
);
FILE
*
internal_log
=
fopen
(
internal_log_path
,
"a"
);
FILE
*
external_log
=
fopen
(
external_log_path
,
"a"
);
FILE
*
external_log
=
fopen
(
external_log_path
,
"a"
);
// Initial snapshot of connections
PMIB_TCPTABLE_OWNER_PID
tcpTable
;
PMIB_TCPTABLE_OWNER_PID
tcpTable
;
DWORD
size
=
0
;
DWORD
size
=
0
;
GetExtendedTcpTable
(
NULL
,
&
size
,
FALSE
,
AF_INET
,
TCP_TABLE_OWNER_PID_ALL
,
0
);
GetExtendedTcpTable
(
NULL
,
&
size
,
FALSE
,
AF_INET
,
TCP_TABLE_OWNER_PID_ALL
,
0
);
...
@@ -165,6 +167,79 @@ int main() {
...
@@ -165,6 +167,79 @@ int main() {
fclose
(
internal_log
);
fclose
(
internal_log
);
fclose
(
external_log
);
fclose
(
external_log
);
free
(
tcpTable
);
free
(
tcpTable
);
// Continuous monitoring loop
DWORD
lastStatusTime
=
GetTickCount
();
const
DWORD
STATUS_INTERVAL
=
5000
;
// 5 seconds
while
(
1
)
{
DWORD
currentTime
=
GetTickCount
();
// Periodic status logging
if
(
currentTime
-
lastStatusTime
>=
STATUS_INTERVAL
)
{
// Get current TCP connections for the monitored process
size
=
0
;
GetExtendedTcpTable
(
NULL
,
&
size
,
FALSE
,
AF_INET
,
TCP_TABLE_OWNER_PID_ALL
,
0
);
tcpTable
=
(
PMIB_TCPTABLE_OWNER_PID
)
malloc
(
size
);
DWORD
socketCount
=
0
;
if
(
GetExtendedTcpTable
(
tcpTable
,
&
size
,
FALSE
,
AF_INET
,
TCP_TABLE_OWNER_PID_ALL
,
0
)
==
NO_ERROR
)
{
for
(
DWORD
i
=
0
;
i
<
tcpTable
->
dwNumEntries
;
i
++
)
{
if
(
tcpTable
->
table
[
i
].
dwOwningPid
==
pid
)
{
socketCount
++
;
}
}
}
// Get process information
HANDLE
hProcess
=
OpenProcess
(
PROCESS_QUERY_INFORMATION
|
PROCESS_VM_READ
,
FALSE
,
pid
);
DWORD
threadCount
=
0
;
DWORD
memoryUsage
=
0
;
if
(
hProcess
)
{
PROCESS_MEMORY_COUNTERS
pmc
;
if
(
GetProcessMemoryInfo
(
hProcess
,
&
pmc
,
sizeof
(
pmc
)))
{
memoryUsage
=
pmc
.
WorkingSetSize
/
1024
;
// KB
}
// Get thread count
HANDLE
hSnapshot
=
CreateToolhelp32Snapshot
(
TH32CS_SNAPTHREAD
,
0
);
if
(
hSnapshot
!=
INVALID_HANDLE_VALUE
)
{
THREADENTRY32
te32
;
te32
.
dwSize
=
sizeof
(
THREADENTRY32
);
if
(
Thread32First
(
hSnapshot
,
&
te32
))
{
do
{
if
(
te32
.
th32OwnerProcessID
==
pid
)
{
threadCount
++
;
}
}
while
(
Thread32Next
(
hSnapshot
,
&
te32
));
}
CloseHandle
(
hSnapshot
);
}
CloseHandle
(
hProcess
);
}
// Get system time for logging
SYSTEMTIME
st
;
GetSystemTime
(
&
st
);
// Print status to console
printf
(
"[%04d-%02d-%02d %02d:%02d:%02d] STATUS - Sockets: %lu, Threads: %lu, Memory: %lu KB
\n
"
,
st
.
wYear
,
st
.
wMonth
,
st
.
wDay
,
st
.
wHour
,
st
.
wMinute
,
st
.
wSecond
,
socketCount
,
threadCount
,
memoryUsage
);
free
(
tcpTable
);
lastStatusTime
=
currentTime
;
}
// Check if process is still running
DWORD
exitCode
;
if
(
GetExitCodeProcess
(
pi
.
hProcess
,
&
exitCode
)
&&
exitCode
!=
STILL_ACTIVE
)
{
printf
(
"Monitored process has terminated.
\n
"
);
break
;
}
Sleep
(
1000
);
// Check every second
}
CloseHandle
(
pi
.
hProcess
);
CloseHandle
(
pi
.
hProcess
);
CloseHandle
(
pi
.
hThread
);
CloseHandle
(
pi
.
hThread
);
return
0
;
return
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment