• 大小: 0.02M
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-05-03
  • 语言: C#
  • 标签: Socket  sOC  获取  ck  数据  

资源简介

通过socket连接扫码抢进而获取扫描的数据

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Diagnostics;
namespace Demo_Net
{
    //本机为服务端
    //下午加一个判断网络是否连接;以及做出相应的判断;
    class Program
    {
        static Socket msock;
        static void Main(string[] args)
        {

            //先判断是否ping通:
            string ips = “10.18.14.111“;
            string str = NetConnect(ips);
            Console.WriteLine(str);
            Console.ReadLine();
        }
        //通过ping的方法判断是否连接;
        private static string NetConnect(string ip)
        {
            Process p = new Process();
            p.StartInfo.FileName = “cmd.exe“;
            p.StartInfo.UseShellExecute = false;
            p.StartInfo.RedirectStandardError = true;
            p.StartInfo.RedirectStandardInput = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.StartInfo.CreateNoWindow = false;
            string pingstr;
            p.Start();
            p.StandardInput.WriteLine(“ping -n 1 “ + ip);
            p.StandardInput.WriteLine(“exit“);
            string strRst = p.StandardOutput.ReadToEnd();
            if (strRst.IndexOf(“(0% 丢失)“) != -1)
            {
                pingstr = “连接成功“;

                //定义socket连接 需要的本机ip以及相应的端口;
                msock = new Socket(AddressFamily.InterNetwork SocketType.Stream ProtocolType.Tcp);
                var localIP = new IPEndPoint(IPAddress.Parse(“10.18.14.23“) 10001);
                msock.Bind(localIP);
                //自己定义最大网络连接数
                msock.Listen(10);
                //新建线程处理;
                Thread th = new Thread(delegate ()
                {
                    Rec();
                });
                th.IsBackground = true;
                th.Start();
            }
            else
            {
                pingstr = “连接超时“;
            }
            p.Close();
            return pingstr;
        }
        //监听是否有链接,新开线程处理
        static void Rec()
        {
            do
            {
                Socket s = msock.Accept();
                Thread th = new Thread(delegate () {
                    Parse(s);
                });
                th.IsBackground = true;
                th.Start();

            } while (true);
        }

        //有链接时处理获取的信息
        static void Parse(Socket s)
        {
            do
            {
                byte[] b = new byte[1000];
                int l = s.Receive(b);
                b = b.Take(l).ToArray();
                string rs = string.Empty;
                for (int i = 0; i < b.Length; i++)
                {
                    rs = rs + b[i].ToString();
                }
                //解码
                Console.WriteLine(Encoding.ASCII.GetString(b 0 l));
            } while (true);

        }
    }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

    ..A..H.     32256  2021-01-26 10:02  SocketAndScaner\.vs\SocketAndScaner\v15\.suo

     文件        189  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\App.config

     文件       7168  2021-01-26 10:02  SocketAndScaner\SocketAndScaner\bin\Debug\SocketAndScaner.exe

     文件        189  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\bin\Debug\SocketAndScaner.exe.config

     文件      19968  2021-01-26 10:02  SocketAndScaner\SocketAndScaner\bin\Debug\SocketAndScaner.pdb

     文件       6752  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件         42  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\SocketAndScaner.csproj.CoreCompileInputs.cache

     文件        571  2021-01-26 09:52  SocketAndScaner\SocketAndScaner\obj\Debug\SocketAndScaner.csproj.FileListAbsolute.txt

     文件       8077  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\SocketAndScaner.csprojAssemblyReference.cache

     文件       7168  2021-01-26 10:02  SocketAndScaner\SocketAndScaner\obj\Debug\SocketAndScaner.exe

     文件      19968  2021-01-26 10:02  SocketAndScaner\SocketAndScaner\obj\Debug\SocketAndScaner.pdb

     文件          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs

     文件          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs

     文件          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs

     文件       3201  2021-01-26 10:34  SocketAndScaner\SocketAndScaner\Program.cs

     文件       1346  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\Properties\AssemblyInfo.cs

     文件       2380  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\SocketAndScaner.csproj

     文件       1144  2021-01-26 09:52  SocketAndScaner\SocketAndScaner.sln

     目录          0  2021-01-26 09:52  SocketAndScaner\.vs\SocketAndScaner\v15\Server\sqlite3

     目录          0  2021-01-26 09:52  SocketAndScaner\.vs\SocketAndScaner\v15\Server

     目录          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj\Debug\TempPE

     目录          0  2021-01-26 09:52  SocketAndScaner\.vs\SocketAndScaner\v15

     目录          0  2021-01-26 09:52  SocketAndScaner\SocketAndScaner\bin\Debug

     目录          0  2021-01-26 09:52  SocketAndScaner\SocketAndScaner\obj\Debug

     目录          0  2021-01-26 09:51  SocketAndScaner\.vs\SocketAndScaner

     目录          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\bin

     目录          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\obj

     目录          0  2021-01-26 09:51  SocketAndScaner\SocketAndScaner\Properties

    ...D.H.         0  2021-01-26 09:51  SocketAndScaner\.vs

     目录          0  2021-01-26 10:34  SocketAndScaner\SocketAndScaner

............此处省略4个文件信息

评论

共有 条评论