首页
社区
课程
招聘
[旧帖] [求助]知道了监听端口,如何能够知道连接到此端口的IP 0.00雪花
发表于: 2009-5-20 11:08 1766

[旧帖] [求助]知道了监听端口,如何能够知道连接到此端口的IP 0.00雪花

2009-5-20 11:08
1766
好像netstat -an那样的效果,知道本地监听端口,能够得出Foreign Address。最后是提供内核编程方法

[课程]Linux pwn 探索篇!

收藏
免费 0
支持
分享
最新回复 (6)
雪    币: 50
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
2
没有人知道吗?
2009-5-22 10:48
0
雪    币: 50
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
3
没有人知道吗
2009-5-25 10:01
0
雪    币: 53
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
4
这个需要去查询mib信息的,给段c#的代码,应该很容易转换成c的

    [StructLayout(LayoutKind.Sequential)]
    public struct MIBOwnerProcessIdTCPTable
    {
        public uint EntryNumber;
        public MIBOwnerProcessIdTCPRow Table;
    }

    [StructLayout(LayoutKind.Sequential)]
    public struct MIBOwnerProcessIdTCPRow
    {
        public uint State;
        public uint LocalAddr;
        public byte LocalPort1;
        public byte LocalPort2;
        public byte LocalPort3;
        public byte LocalPort4;
        public uint RemoteAddr;
        public byte RemotePort1;
        public byte RemotePort2;
        public byte RemotePort3;
        public byte remotePort4;
        public int OwnerProcessId;
    }

        [DllImport("iphlpapi.dll", SetLastError = true)]
        public static extern WinApiSystemErrorCode GetExtendedTcpTable(IntPtr pTcpTable,
                                                                       ref int dwOutBufLen,
                                                                       bool sort,
                                                                       WinApiAddressFamilies addressFamily,
                                                                       WinApiMIBTCPTableTypes tableType,
                                                                       int reserved);

        /// <summary>
        /// [Helper] Get all the TCP connections with process information
        /// </summary>
        public static MIBOwnerProcessIdTCPRow[] GetAllMIBOwnerProcessIdTCPRows()
        {
            MIBOwnerProcessIdTCPRow[] rows;
            int bufferSize = 0;

            // how much memory do we need?
            WinApiSystemErrorCode errorCode = GetExtendedTcpTable(IntPtr.Zero,
                                                                  ref bufferSize,
                                                                  true,
                                                                  WinApiAddressFamilies.Internet,
                                                                  WinApiMIBTCPTableTypes.OwnerProcessIdAll,
                                                                  0);

            IntPtr bufferTable = Marshal.AllocHGlobal(bufferSize);

            try
            {
                errorCode = GetExtendedTcpTable(bufferTable,
                                                ref bufferSize,
                                                true,
                                                WinApiAddressFamilies.Internet,
                                                WinApiMIBTCPTableTypes.OwnerProcessIdAll,
                                                0);

                if (errorCode != WinApiSystemErrorCode.Success)
                {
                    return null;
                }

                // get the number of entries in the table
                MIBOwnerProcessIdTCPTable table = (MIBOwnerProcessIdTCPTable)Marshal.PtrToStructure(bufferTable, typeof(MIBOwnerProcessIdTCPTable));
                IntPtr rowPtr = (IntPtr)((long)bufferTable + Marshal.SizeOf(table.EntryNumber));

                rows = new MIBOwnerProcessIdTCPRow[table.EntryNumber];

                for (int i = 0; i < rows.Length; i++)
                {
                    rows[i] = (MIBOwnerProcessIdTCPRow)Marshal.PtrToStructure(rowPtr, typeof(MIBOwnerProcessIdTCPRow));
                    rowPtr = (IntPtr)((long)rowPtr + Marshal.SizeOf(typeof(MIBOwnerProcessIdTCPRow)));
                }

                return rows;
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                Marshal.FreeHGlobal(bufferTable);
            }
        }
2009-5-25 20:03
0
雪    币: 4
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
学习了,谢谢
2009-5-25 20:13
0
雪    币: 63
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
看不懂,正在学习。
2009-5-26 19:25
0
雪    币: 1556
活跃值: (310)
能力值: ( LV4,RANK:40 )
在线值:
发帖
回帖
粉丝
7
mib是啥?
2009-5-26 19:57
0
游客
登录 | 注册 方可回帖
返回
//