社区
C#
帖子详情
已知计算机ip地址,如何用Socket枚举局域网中活动的计算机名以及当前用户名?
wyfzy521
2003-08-26 09:52:02
以前下载过一个这样的例程,后来不小心删除了,哪位大侠能够提供点这方面的信息?
那个程序好像用了两个线程,然后给局域网一定范围内的机器发送数据,返回的数据中包含该机器的名称和当前的用户名。
...全文
96
11
打赏
收藏
已知计算机ip地址,如何用Socket枚举局域网中活动的计算机名以及当前用户名?
以前下载过一个这样的例程,后来不小心删除了,哪位大侠能够提供点这方面的信息? 那个程序好像用了两个线程,然后给局域网一定范围内的机器发送数据,返回的数据中包含该机器的名称和当前的用户名。
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
11 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
nice90
2003-09-07
打赏
举报
回复
mark
zhbname
2003-09-03
打赏
举报
回复
up
derek
2003-09-02
打赏
举报
回复
当前的用户名! 這個是難題
我也提過類似的問題,見:
http://expert.csdn.net/Expert/topic/2107/2107495.xml?temp=.1838953
jcaomao
2003-09-01
打赏
举报
回复
我记得api里有,你可以查查,这样效率比较高。
如果不是win98的机器,也可以用wmi
kuangren
2003-09-01
打赏
举报
回复
可以从WMI和注册表获取
angxain
2003-08-30
打赏
举报
回复
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Net;
using System.Threading;
namespace WindowsApplication5
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button3;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.label1 = new System.Windows.Forms.Label();
this.button3 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 16);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 24);
this.button1.TabIndex = 0;
this.button1.Text = "本機IP地址";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(104, 16);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 24);
this.button2.TabIndex = 1;
this.button2.Text = "遠端電腦IP地址";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(112, 64);
this.textBox2.Name = "textBox2";
this.textBox2.TabIndex = 3;
this.textBox2.Text = "";
this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(8, 112);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(248, 160);
this.richTextBox1.TabIndex = 4;
this.richTextBox1.Text = "";
this.richTextBox1.TextChanged += new System.EventHandler(this.richTextBox1_TextChanged);
//
// label1
//
this.label1.Location = new System.Drawing.Point(0, 64);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(100, 16);
this.label1.TabIndex = 5;
this.label1.Text = "IP地址:";
this.label1.TextAlign = System.Drawing.ContentAlignment.TopCenter;
//
// button3
//
this.button3.Location = new System.Drawing.Point(352, 64);
this.button3.Name = "button3";
this.button3.TabIndex = 6;
this.button3.Text = "button3";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
this.ClientSize = new System.Drawing.Size(544, 317);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.button3,
this.label1,
this.richTextBox1,
this.textBox2,
this.button2,
this.button1});
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
IPHostEntry myHost= new IPHostEntry();
try
{
myHost=Dns.GetHostByName(Dns.GetHostName());
for(int i=0;i<myHost.AddressList.Length;i++)
{
richTextBox1.AppendText("±??uIPμOO·"+myHost.AddressList[i].ToString()+"\r");
}
}
catch(Exception error)
{
MessageBox.Show(error.Message);
}
}
private void richTextBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
private void textBox2_TextChanged(object sender, System.EventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
IPHostEntry myDnsToIP = new IPHostEntry();
myDnsToIP = Dns.Resolve(textBox2.Text.ToString());
for(int i=0;i<myDnsToIP.AddressList.Length;i++)
{
richTextBox1.AppendText(textBox2.Text+"μAIPμOO·Ia"+myDnsToIP.AddressList[i].ToString()+"\r");
}
}
private void button3_Click(object sender, System.EventArgs e)
{
Thread thScan = new Thread(new ThreadStart(ScanTarget));
thScan.Start();
}
private void ScanTarget()
{
string strIPAddress= "192.168.100.";
for(int i=1;i<20;i++)
{
string strScanIPAdd = strIPAddress+i.ToString();
IPAddress myScanIP= IPAddress.Parse(strScanIPAdd);
try
{
IPHostEntry myScanHost = Dns.GetHostByAddress(myScanIP);
string strHostName= myScanHost.HostName.ToString();
richTextBox1.AppendText(strScanIPAdd+"->"+strHostName+"\r");
}
catch(Exception error)
{
MessageBox.Show(error.Message);
}
}
}
private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
{
}
private void numericUpDown3_ValueChanged(object sender, System.EventArgs e)
{
}
private void numericUpDown2_ValueChanged(object sender, System.EventArgs e)
{
}
private void numericUpDown4_ValueChanged(object sender, System.EventArgs e)
{
}
private void numericUpDown5_ValueChanged(object sender, System.EventArgs e)
{
}
}
}
goodluck001
2003-08-30
打赏
举报
回复
private void HostsInit()
{
IPHostEntry host=new IPHostEntry();
for(int i=1;i<=254;i++)
Dns.BeginGetHostByName("192.168.0."+i,new AsyncCallback(HostsInit),host);
}
private void HostsInit(IAsyncResult ar)
{
try
{
IPHostEntry host=Dns.EndGetHostByName(ar);
IPHostEntry host1=Dns.GetHostByAddress(host.AddressList[0]);
if(host1.HostName.Trim() != Me)//Me是本地计算机
cb_host.Items.Add(host1.HostName);//cb_host 是一个CombBox,用于记录局域网中的计算机
}
catch{}
}
goodluck001
2003-08-30
打赏
举报
回复
private void HostsInit()
{
IPHostEntry host=new IPHostEntry();
for(int i=1;i<=254;i++)
Dns.BeginGetHostByName("192.168.0."+i,new AsyncCallback(HostsInit),host);
}
private void HostsInit(IAsyncResult ar)
{
try
{
IPHostEntry host=Dns.EndGetHostByName(ar);
IPHostEntry host1=Dns.GetHostByAddress(host.AddressList[0]);
if(host1.HostName.Trim() != Me)//Me是本地计算机
cb_host.Items.Add(host1.HostName);//cb_host 是一个CombBox,用于记录局域网中的计算机
}
catch{}
}
jn_sly
2003-08-28
打赏
举报
回复
dns.resolve()
_weiKun_
2003-08-27
打赏
举报
回复
用远程的Socket中的EndPoint来判断.向客户端发送消息,如连通则发送确认信息,服务器端看是否有返回信息即可.
wzzw
2003-08-26
打赏
举报
回复
刚好最近在作这方面的事情,我用的方法是SOCKET连接地址列表中的每个终端,然后判断异常类型
区块链之智能合约快速入门
合约是一个活在以太坊系统里的自动代理人,他有一个自己的以太币地址,当用户向合约的地址里发送一笔交易后,该合约就被激活,然后根据交易
中
的额外信息,合约会运行自身的代码,最后返回一个结果,这个结果可能是从...
计算机
考研复试面试问答整理(
计算机
网络、数据结构、操作系统、数据库、热点概念)
要求内存
中
可用存储单元的地址必须是连续的。 优点:存储密度大(=1),易于查找和修改。 缺点:插入或删除元素时不方便;存储空间利用率低,预先分配内存可能造成存储空间浪费。 ②链式存储时,相邻数据元素可随意...
网络安全--主机探测教程
提示:文章写完后,目录可以自动生成,如何生成可...重点用法:SMB
枚举
六、nmap1.用途2.常见用法3.探测结果4.重点用法:nmap脚本引擎功能七、amap1.用途2.常见用法3.探测结果 实验目的 学习常用的主机探测命令,查.
实施运维企业面试题-5
1 请描述 TCP/IP 协议
中
主机与主机之间通信的三要素 参考答案 IP 地址(IP address) 子网掩码(subnet mask) IP 路由(IP router) 2 请描述 IP 地址的分类及每一类的范围 参考答案 A 类 1-26 B 类 128-191 C 类 ...
信息收集(Web 安全)
IP地址
通常由四个十进制数构成,每个数的取值范围是0到255,192.168.1.1,
IP地址
可以是公共的,用于在互联网上进行通信,也可以是私有的,用于在
局域网
内进行通信。而域
名
是用于在互联网上标识和定位特定网站或服务...
C#
110,534
社区成员
642,576
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章