Browse Source

sample python socket app

master
Sebastian Rieger 8 years ago
parent
commit
3fb8b72ef1
  1. 315
      GIT-VIRL-HS-Fulda/Kommunikationsnetze und -protokolle (Bachelor AI)/kommprot-lab3-clientserverapp.virl

315
GIT-VIRL-HS-Fulda/Kommunikationsnetze und -protokolle (Bachelor AI)/kommprot-lab3-clientserverapp.virl

@ -0,0 +1,315 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<topology xmlns="http://www.cisco.com/VIRL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaVersion="0.95" xsi:schemaLocation="http://www.cisco.com/VIRL https://raw.github.com/CiscoVIRL/schema/v0.95/virl.xsd">
<extensions>
<entry key="management_network" type="String">exclusive</entry>
<entry key="AutoNetkit.enable_cdp" type="Boolean">true</entry>
</extensions>
<node name="client1" type="SIMPLE" subtype="lxc" location="340,301">
<extensions>
<entry key="config" type="String">#cloud-config&#xD;
bootcmd:&#xD;
- ln -s -t /etc/rc.d /etc/rc.local&#xD;
hostname: client&#xD;
manage_etc_hosts: true&#xD;
runcmd:&#xD;
- systemctl start rc-local&#xD;
- sed -i '/^\s*PasswordAuthentication\s\+no/d' /etc/ssh/sshd_config&#xD;
- echo "UseDNS no" &gt;&gt; /etc/ssh/sshd_config&#xD;
- service ssh restart&#xD;
- service sshd restart&#xD;
users:&#xD;
- default&#xD;
- gecos: User configured by VIRL Configuration Engine 0.23.9&#xD;
lock-passwd: false&#xD;
name: cisco&#xD;
plain-text-passwd: cisco&#xD;
shell: /bin/bash&#xD;
ssh-authorized-keys:&#xD;
- VIRL-USER-SSH-PUBLIC-KEY&#xD;
sudo: ALL=(ALL) ALL&#xD;
write_files:&#xD;
- path: /etc/systemd/system/dhclient@.service&#xD;
content: |&#xD;
[Unit]&#xD;
Description=Run dhclient on %i interface&#xD;
After=network.target&#xD;
[Service]&#xD;
Type=oneshot&#xD;
ExecStart=/sbin/dhclient %i -pf /var/run/dhclient.%i.pid -lf /var/lib/dhclient/dhclient.%i.lease&#xD;
RemainAfterExit=yes&#xD;
owner: root:root&#xD;
permissions: '0644'&#xD;
- path: /etc/rc.local&#xD;
owner: root:root&#xD;
permissions: '0755'&#xD;
content: |-&#xD;
#!/bin/sh&#xD;
ifconfig eth1 up 10.0.0.20 netmask 255.255.0.0&#xD;
route add -host 192.168.0.1 gw 10.0.0.1 dev eth1&#xD;
route add -net 10.0.0.0/16 gw 10.0.0.1 dev eth1&#xD;
route add default gw 10.0.0.1&#xD;
echo "nameserver 8.8.8.8" &gt;/etc/resolv.conf&#xD;
exit 0&#xD;
- path: /home/cisco/udpserver.py&#xD;
owner: cisco:cisco&#xD;
permissions: '0755'&#xD;
content: |-&#xD;
#!/usr/bin/python&#xD;
from socket import *&#xD;
&#xD;
# UDP Port auf dem der Server lauschen soll...&#xD;
serverPort = 17000&#xD;
&#xD;
# Server-Socket als Internet (INET) UDP (DGRAM) erzeugen und an o.g. Port binden&#xD;
serverSocket = socket(AF_INET, SOCK_DGRAM)&#xD;
serverSocket.bind(("", serverPort))&#xD;
print "UDP Server ist bereit fuer den Empfang von Daten..."&#xD;
&#xD;
# Endlosschleife&#xD;
while 1:&#xD;
# Eingehende Nachrichten von Clients empfangen&#xD;
message, clientAddress = serverSocket.recvfrom(2048)&#xD;
# Alle Buchstaben der Nachricht in Grossbuchstaben umwandeln und an den&#xD;
# Client zuruecksenden&#xD;
modifiedMessage = message.upper()&#xD;
serverSocket.sendto(modifiedMessage, clientAddress)&#xD;
- path: /home/cisco/udpclient.py&#xD;
owner: cisco:cisco&#xD;
permissions: '0755'&#xD;
content: |-&#xD;
#!/usr/bin/python&#xD;
from socket import *&#xD;
&#xD;
# Server-Adresse und Port&#xD;
serverName = "localhost"&#xD;
serverPort = 17000&#xD;
&#xD;
# Client Socket (IP, UDP) oeffnen&#xD;
clientSocket = socket(AF_INET, SOCK_DGRAM)&#xD;
&#xD;
# Nachricht vom Benutzer erfragen und versenden&#xD;
message = raw_input("UDP Nachricht in Kleinbuchstaben eingeben:")&#xD;
clientSocket.sendto(message,(serverName, serverPort))&#xD;
&#xD;
# Antwort des Server aus Socket lesen und ausgeben&#xD;
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)&#xD;
print "Antwort des Servers: ", modifiedMessage&#xD;
raw_input("Fertig...")&#xD;
&#xD;
# Verbindung schliessen&#xD;
clientSocket.close()&#xD;
- path: /home/cisco/tcpserver.py&#xD;
owner: cisco:cisco&#xD;
permissions: '0755'&#xD;
content: |-&#xD;
#!/usr/bin/python&#xD;
from socket import *&#xD;
&#xD;
# TCP Port auf dem der Server lauschen soll...&#xD;
serverPort = 17000&#xD;
# Server-Socket als Internet (INET) TCP (STREAM) erzeugen und an o.g. Port binden&#xD;
serverSocket = socket(AF_INET,SOCK_STREAM)&#xD;
serverSocket.bind(("",serverPort))&#xD;
serverSocket.listen(1)&#xD;
print "TCP Server ist bereit fuer den Empfang von Daten..."&#xD;
&#xD;
# Endlosschleife&#xD;
while 1:&#xD;
# Eingehende Nachrichten akzeptieren und von Clients empfangen&#xD;
connectionSocket, addr = serverSocket.accept()&#xD;
sentence = connectionSocket.recv(1024)&#xD;
# Alle Buchstaben der Nachricht in Grossbuchstaben umwandeln und an den&#xD;
# Client zuruecksenden&#xD;
capitalizedSentence = sentence.upper()&#xD;
connectionSocket.send(capitalizedSentence)&#xD;
# Verbindung schliessen&#xD;
connectionSocket.close()&#xD;
- path: /home/cisco/tcpclient.py&#xD;
owner: cisco:cisco&#xD;
permissions: '0755'&#xD;
content: |-&#xD;
#!/usr/bin/python&#xD;
from socket import *&#xD;
&#xD;
# Serveradresse und TCP Port auf den der Server hoert...&#xD;
serverName = "localhost"&#xD;
serverPort = 17000&#xD;
# Socket fuer IP (INET) und TCP (STREAM) konfigurieren&#xD;
clientSocket = socket(AF_INET, SOCK_STREAM)&#xD;
clientSocket.connect((serverName,serverPort))&#xD;
&#xD;
# Nachricht vom Benutzer abfragen und an den Server senden&#xD;
sentence = raw_input("TCP Nachricht in Kleinbuchstaben eingeben:")&#xD;
clientSocket.send(sentence)&#xD;
&#xD;
# Antwort des Servers ausgeben&#xD;
modifiedSentence = clientSocket.recv(1024)&#xD;
print "Antwort des Servers:", modifiedSentence&#xD;
raw_input("Fertig...")&#xD;
&#xD;
# Verbindung schliessen&#xD;
clientSocket.close()&#xD;
</entry>
</extensions>
<interface id="0" name="eth1" ipv4="10.0.0.2" netPrefixLenV4="16"/>
</node>
<node name="server1" type="SIMPLE" subtype="lxc" location="584,301">
<extensions>
<entry key="config" type="String">#cloud-config&#xD;
bootcmd:&#xD;
- ln -s -t /etc/rc.d /etc/rc.local&#xD;
hostname: server&#xD;
manage_etc_hosts: true&#xD;
runcmd:&#xD;
- systemctl start rc-local&#xD;
- sed -i '/^\s*PasswordAuthentication\s\+no/d' /etc/ssh/sshd_config&#xD;
- echo "UseDNS no" &gt;&gt; /etc/ssh/sshd_config&#xD;
- service ssh restart&#xD;
- service sshd restart&#xD;
users:&#xD;
- default&#xD;
- gecos: User configured by VIRL Configuration Engine 0.23.9&#xD;
lock-passwd: false&#xD;
name: cisco&#xD;
plain-text-passwd: cisco&#xD;
shell: /bin/bash&#xD;
ssh-authorized-keys:&#xD;
- VIRL-USER-SSH-PUBLIC-KEY&#xD;
sudo: ALL=(ALL) ALL&#xD;
write_files:&#xD;
- path: /etc/systemd/system/dhclient@.service&#xD;
content: |&#xD;
[Unit]&#xD;
Description=Run dhclient on %i interface&#xD;
After=network.target&#xD;
[Service]&#xD;
Type=oneshot&#xD;
ExecStart=/sbin/dhclient %i -pf /var/run/dhclient.%i.pid -lf /var/lib/dhclient/dhclient.%i.lease&#xD;
RemainAfterExit=yes&#xD;
owner: root:root&#xD;
permissions: '0644'&#xD;
- path: /etc/rc.local&#xD;
owner: root:root&#xD;
permissions: '0755'&#xD;
content: |-&#xD;
#!/bin/sh&#xD;
ifconfig eth1 up 10.0.0.30 netmask 255.255.0.0&#xD;
route add -host 192.168.0.1 gw 10.0.0.1 dev eth1&#xD;
route add -net 10.0.0.0/16 gw 10.0.0.1 dev eth1&#xD;
route add default gw 10.0.0.1&#xD;
echo "nameserver 8.8.8.8" &gt;/etc/resolv.conf&#xD;
exit 0&#xD;
</entry>
</extensions>
<interface id="0" name="eth1" ipv4="10.0.0.3" netPrefixLenV4="16"/>
</node>
<node name="switch1" type="SIMPLE" subtype="Unmanaged Switch" location="446,227">
<interface id="0" name="link1"/>
<interface id="1" name="link2"/>
<interface id="2" name="link3"/>
</node>
<node name="router1" type="SIMPLE" subtype="IOSv" location="446,106">
<extensions>
<entry key="AutoNetkit.mgmt_ip" type="string"></entry>
<entry key="Auto-generate config" type="Boolean">false</entry>
<entry key="config" type="String">! IOS Config generated on 2016-12-05 08:28&#xD;
! by autonetkit_0.23.5&#xD;
!&#xD;
hostname router1&#xD;
boot-start-marker&#xD;
boot-end-marker&#xD;
!&#xD;
vrf definition Mgmt-intf&#xD;
!&#xD;
address-family ipv4&#xD;
exit-address-family&#xD;
!&#xD;
address-family ipv6&#xD;
exit-address-family&#xD;
!&#xD;
!&#xD;
!&#xD;
no aaa new-model&#xD;
!&#xD;
!&#xD;
ip cef&#xD;
ipv6 unicast-routing&#xD;
ipv6 cef&#xD;
!&#xD;
!&#xD;
service timestamps debug datetime msec&#xD;
service timestamps log datetime msec&#xD;
no service password-encryption&#xD;
no service config&#xD;
enable password cisco&#xD;
ip classless&#xD;
ip subnet-zero&#xD;
no ip domain lookup&#xD;
ip domain name virl.info&#xD;
crypto key generate rsa modulus 768&#xD;
ip ssh server algorithm authentication password&#xD;
username cisco privilege 15 secret cisco&#xD;
line vty 0 4&#xD;
transport input ssh telnet&#xD;
exec-timeout 720 0&#xD;
password cisco&#xD;
login local&#xD;
line con 0&#xD;
password cisco&#xD;
!&#xD;
cdp run&#xD;
!&#xD;
!&#xD;
interface Loopback0&#xD;
description Loopback&#xD;
ip address 192.168.0.1 255.255.255.255&#xD;
!&#xD;
interface GigabitEthernet0/0&#xD;
description OOB Management&#xD;
vrf forwarding Mgmt-intf&#xD;
! Configured on launch&#xD;
no ip address&#xD;
cdp enable&#xD;
duplex full&#xD;
speed auto&#xD;
no shutdown&#xD;
!&#xD;
interface GigabitEthernet0/1&#xD;
description to Internet&#xD;
no ip address&#xD;
ip nat outside&#xD;
cdp enable&#xD;
duplex full&#xD;
speed auto&#xD;
no shutdown&#xD;
!&#xD;
interface GigabitEthernet0/2&#xD;
description to switch1&#xD;
ip address 10.0.0.1 255.255.0.0&#xD;
ip nat inside&#xD;
cdp enable&#xD;
ip ospf cost 1&#xD;
duplex full&#xD;
speed auto&#xD;
no shutdown&#xD;
!&#xD;
! NAT stuff&#xD;
!&#xD;
ip nat inside source list 1 interface GigabitEthernet0/1 overload&#xD;
ip route 0.0.0.0 0.0.0.0 172.16.1.1&#xD;
access-list 1 permit 10.0.0.0 0.0.255.255&#xD;
!&#xD;
end</entry>
</extensions>
<interface id="0" name="GigabitEthernet0/1"/>
<interface id="1" name="GigabitEthernet0/2" ipv4="10.0.0.1" netPrefixLenV4="16"/>
</node>
<node name="Internet" type="ASSET" subtype="FLAT" location="337,55">
<interface id="0" name="link0"/>
</node>
<annotations/>
<connection dst="/virl:topology/virl:node[4]/virl:interface[1]" src="/virl:topology/virl:node[5]/virl:interface[1]"/>
<connection dst="/virl:topology/virl:node[3]/virl:interface[1]" src="/virl:topology/virl:node[4]/virl:interface[2]"/>
<connection dst="/virl:topology/virl:node[1]/virl:interface[1]" src="/virl:topology/virl:node[3]/virl:interface[2]"/>
<connection dst="/virl:topology/virl:node[2]/virl:interface[1]" src="/virl:topology/virl:node[3]/virl:interface[3]"/>
</topology>
Loading…
Cancel
Save