| |

VerySource

 Forgot password?
 Register
Search
View: 919|Reply: 9

C # query method

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-3-5 22:00:01
| Show all posts |Read mode
Hello everyone:
    Previously, I used 255 threads to scan the LAN host. The function was implemented, but it was not fast! I want to use C # to directly query the switch to obtain LAN host information. How can this be achieved? Hope you guys give pointers! Be grateful!
Reply

Use magic Report

0

Threads

16

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-5-23 12:45:01
| Show all posts
Unless the switch manufacturer reserves this functional interface for you, it is basically not expected.
If your switch is advanced enough, telnet directly to the switch to view the mac table, there will be some basic information, which should be able to satisfy you.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-5-24 11:15:01
| Show all posts
Can you post the code for scanning the LAN host with 255 threads? Learn to learn!
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-7-17 16:30:01
| Show all posts
What I do is a LAN information exchange tool, there are a lot of codes, in order to discuss the need, I just extract the multi-thread scanning LAN IP part and discuss with everyone! The program is definitely not optimized, I hope you don’t laugh at it!

private void GetLanHost()
{
//Get the LAN host and add it to ComboBox1
//tempLocalIP = Dns.GetHostByName(LocalHostName).AddressList[0].ToString();
//The "LocalHostIp" is not used directly here because it may change in the future! So use tempLocalIP;
strLanIpFront = tempLocalIP.Substring(0,tempLocalIP.LastIndexOf("."));//Retrieve the first three segments of the local IP address
comboBox1.Text = "";
comboBox1.Items.Clear();
MyThread = new Thread[255];
for(int i=0;i<255;i++)//Enable 255 threads to scan the LAN host IP and machine name
{
MyThread[i] = new Thread(new ThreadStart(Scan));
MyThread[i].Name = i.ToString();
MyThread[i].Start();
if(!MyThread[i].Join(120))
{
MyThread[i].Abort();
}
}
}

private void Scan()
{
//How to scan LAN_IP
IPAddress LanIp = IPAddress.Parse(strLanIpFront + "." + Thread.CurrentThread.Name.ToString());
IPHostEntry LanHostDns = null;
//The "LocalHostIp" is not used directly here because it may change in the future! So use tempLocalIP;
if(LanIp.ToString() != tempLocalIP) //Do not scan this machine
{
try
{
LanHostDns = Dns.GetHostByAddress(LanIp);
lock(comboBox1)
{
comboBox1.Items.Add("LAN:" + LanIp.ToString() + "(" + LanHostDns.HostName.ToString() + ")");
}
}
catch
{}
}
}
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-7-17 21:15:01
| Show all posts
Where there is such a scan, generally use arp scan, which can be scanned in one second
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-8-6 10:15:01
| Show all posts
arp scan? Good! Friends, can you give me sample code? Thank you!
Reply

Use magic Report

0

Threads

16

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-8-6 11:30:01
| Show all posts
arp scan?
I haven’t heard of it, I don’t understand the arp protocol, let’s listen...
Reply

Use magic Report

0

Threads

2

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-6 14:15:01
| Show all posts
If the switch supports http query, just pretend to be a browser to fetch this page directly, and then analyze the resulting HTML
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-8-7 13:00:01
| Show all posts
Refer to the following practices. In addition, there is no need for 255 threads, just one thread scan. The creation and scheduling of 255 threads will consume a lot of system resources, which may be a reason for the low performance!

public class CLsArp
{
#region APIs
[DllImport("iphlpapi.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern Int32 SendARP(UInt32 udwDestIP,UInt32 udwSrcIP,byte[] pMacAddr,ref Int32 PhyAddrLen);

private const Int32 NUMBER_OF_PHYSICAL_ADDRESS_BYTES = 6;
#endregion

public CLsArp()
{
}

public static byte[] GetComputerMacAddr(UInt32 dwIP)
{
byte[] abMacAddr = null;

Int32 dwPhyAddrLen = 0;
To
try
{
abMacAddr = new byte[NUMBER_OF_PHYSICAL_ADDRESS_BYTES];
dwPhyAddrLen = abMacAddr.Length;

if (SendARP(dwIP,0,abMacAddr, ref dwPhyAddrLen) != 0)
{
//Get Error!Reset byte array to null
abMacAddr = null;
}
}
catch
{
abMacAddr = null;
}

return abMacAddr;
}
}
Reply

Use magic Report

0

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-8-8 15:00:01
| Show all posts
If you don’t understand it, search on the Internet. This protocol is public and not a secret. As for how to send arp protocol data, I suggest you use the winpcap function library, which is free to open the original. There is a c# packaging library for winpcap on codeproject, which is very convenient. , Send an arp request packet to a machine, if it is turned on and on the network, it will immediately send you a response packet, you can search all the machines according to the received response packet, because most firewalls do not intercept the arp protocol Function, so this method can penetrate the firewall with the best effect.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list