社区
C#
帖子详情
已知计算机ip地址,如何用Socket枚举局域网中活动的计算机名以及当前用户名?
wyfzy521
2003-08-26 09:52:02
以前下载过一个这样的例程,后来不小心删除了,哪位大侠能够提供点这方面的信息?
那个程序好像用了两个线程,然后给局域网一定范围内的机器发送数据,返回的数据中包含该机器的名称和当前的用户名。
...全文
94
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、顺序存储和链式存储优缺点比较 ① 顺序存储时,相邻数据元素的存放地址也相邻(逻辑与物理统一);要求内存
中
可用存储单元的地址必须是连续的。 优点:存储密度大(=1),易于查找和修改。 缺点:插入或删除元素时不方便;存储空间利用率低,预先分配内存可能造成存储空间浪费。 ②链式存储时,相邻数据元素可随意存放,但所占存储空间分两部分,一部分存放结点值,另一部分存放表示结点间关系的指针 优点:插入或删除元素时很方便,使用灵活,存储空间利用率高。 缺点:存储密度小(<1),查找和修改需要遍历整个链表
实施运维企业面试题-5
NETWORK 1 请描述 TCP/IP 协议
中
主机与主机之间通信的三要素 参考答案 IP 地址(IP address) 子网掩码(subnet mask) IP 路由(IP router) 2 请描述 IP 地址的分类及每一类的范围 参考答案 A 类 1-26 B 类 128-191 C 类 192-223 D 类 224-239 组播(多播) E 类 240-254 科研 3 请描述 A、B、C 三类 IP 地址的默认子网掩码 参考答案 A 类 255.0.0.0 B 类 255.255.0.0 C 类
运维面试题(1024水篇)
NETWORK 1 请描述TCP/IP协议
中
主机与主机之间通信的三要素 参考答案
IP地址
(IP address) 子网掩码(subnet mask) IP路由(IP router) 2 请描述
IP地址
的分类及每一类的范围 参考答案 A类1-26 B类128-191 C类192-223 D类224-239组播(多播) E类240-254科研 3 请描述A、B、C三类
IP地址
的默认子网掩码 参考答案 A类255.0.0.0 B类255.255.0.0 C类255.255.255.0 4 请描述预留给企业的私有
计算机
网络知识点概括
第一章 概述 1.1
计算机
网络的一些相关知识 三网------电信网络、有线电视网络、
计算机
网络 网络融合------将三种网络的功能融合在一起
计算机
网络------也是一种通信基础设施,与其他两种网络不同的是
计算机
网络的终端设备是功能强大的
计算机
1.2 互联网概述 网络,互连(非"联")网,因特网的概念 起源于美国的因特网,现在是世界上最大的国际性
计算机
网络。 网络由若干个节点和连接这些节点的链路组成(节点可以是
计算机
、集线器、交换机、路由器等)。 网络和网络之间通过
计算机
考研复试题(近十万字)
本文为博主考研期间准备的知识点,涵盖本科大部分内容,其
中
大部分在复试期间准备的。复试非常非常重要,准备的越充分越好,希望大家重视。本文内容为本人自己总结及从其他地方看到的一些资源。格式凌乱,后续会慢慢整理,祝各位前程似锦!
C#
110,502
社区成员
642,567
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章