Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GNS3_unikernel_testbed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NGUYEN Do Duc Anh
GNS3_unikernel_testbed
Commits
91d259f0
Commit
91d259f0
authored
9 months ago
by
anhndd
Browse files
Options
Downloads
Patches
Plain Diff
first commit
parents
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ubuntu_base/vc_server.py
+66
-0
66 additions, 0 deletions
ubuntu_base/vc_server.py
with
66 additions
and
0 deletions
ubuntu_base/vc_server.py
0 → 100644
+
66
−
0
View file @
91d259f0
import
socket
import
time
,
sys
,
queue
import
threading
import
subprocess
# Configuration
IP_server
=
"
192.168.123.1
"
LISTEN_PORT
=
12346
# Specify the port number to listen on
ip_queue
=
queue
.
Queue
()
array_point_save
=
[]
num_machine
=
0
map_point
=
{}
OUTPUT_FILE
=
"
measurement.txt
"
def
read_and_write_points
():
global
ip_queue
,
num_machine
while
True
:
try
:
time_ip
=
ip_queue
.
get
()
if
time_ip
[
1
]
not
in
map_point
:
map_point
[
time_ip
[
1
]]
=
time_ip
[
0
]
array_point_save
.
append
(
time_ip
)
with
open
(
OUTPUT_FILE
,
"
w
"
)
as
file
:
file
.
write
(
str
(
array_point_save
))
print
(
"
saved
"
,
array_point_save
)
len_actual
=
len
(
array_point_save
)
print
(
len_actual
,
"
machine infected
"
)
if
num_machine
==
len_actual
:
command
=
"
nc -q 5
"
+
IP_server
+
"
12345 < measurement.txt
"
print
(
"
run
"
,
command
)
try
:
subprocess
.
run
(
command
,
shell
=
True
,
check
=
True
)
print
(
"
done
"
)
except
subprocess
.
CalledProcessError
as
e
:
print
(
f
"
Error executing command:
{
e
}
"
)
else
:
print
(
"
duplicate
"
,
time_ip
[
1
])
#time.sleep(1)
except
queue
.
Empty
:
pass
def
main
():
global
ip_queue
,
num_machine
if
len
(
sys
.
argv
)
>
1
:
num_machine
=
int
(
sys
.
argv
[
1
])
else
:
return
thread
=
threading
.
Thread
(
target
=
read_and_write_points
)
thread
.
daemon
=
True
thread
.
start
()
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
server_socket
:
server_socket
.
bind
((
'
0.0.0.0
'
,
LISTEN_PORT
))
server_socket
.
listen
()
print
(
f
"
Listening for incoming connections on port
{
LISTEN_PORT
}
...
"
)
while
True
:
client_socket
,
client_address
=
server_socket
.
accept
()
ip_queue
.
put
([
time
.
time
(),
client_address
[
0
]])
#print(f"Connection {connection_count}: {client_address[0]}")
if
__name__
==
"
__main__
"
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment