Skip to content

Commit

Permalink
Parse IP Endpoint from command line
Browse files Browse the repository at this point in the history
  • Loading branch information
bonk-dev committed Aug 6, 2024
1 parent 7722799 commit e5b99c5
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions HarpoS7.PoC/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Sockets;
using System.Net;
using System.Net.Sockets;
using System.Text;
using HarpoS7;
using HarpoS7.Auth;
Expand All @@ -13,25 +14,30 @@
// in a real library/app you would obviously serialize/deserialize these dynamically

var readBuffer = new byte[1024];
const string plcHost = "192.168.1.10";
const int plcS7Port = 102;
if (args.Length < 1 || !IPEndPoint.TryParse(args[0], out var endPoint))
{
Console.WriteLine("Usage: HarpoS7.PoC ip_address:port");
Console.WriteLine("Example: HarpoS7.PoC 192.168.1.10:102");

return;
}

// Connect to the PLC
using var client = new TcpClient();

try
{
await client.ConnectAsync(plcHost, plcS7Port);
await client.ConnectAsync(endPoint);
}
catch (SocketException ex)
{
Console.WriteLine($"[-] Could not connect to {plcHost}:{plcS7Port}");
Console.WriteLine($"[-] Could not connect to {endPoint}");
Console.WriteLine($"[-] Exception message: {ex.Message}");

return;
}

Console.WriteLine($"[+] Connected to {plcHost}:{plcS7Port}");
Console.WriteLine($"[+] Connected to {endPoint}");
var stream = client.GetStream();

// Send COTP Connection Request
Expand Down

0 comments on commit e5b99c5

Please sign in to comment.