I am working on an ASP.NEt mvc web application, that stores data regarding network devices.but I need to know if there is a global format for these numbers:-
IP address
MAC address
VLanID
subnetmask
And is there any data annotations I can use to implement data validation for these numbers?
Thanks
For IP Address:
IPAddress ip = new IPAddress((long)ips);
return ip.ToString();
To store IP address, read this
For MacAddress, i dont know any existing formats. but you can take it from string.
string macAddStr = "00E0EE00EE00";
string macAddStrNew = macAddStr;
int insertedCount = 0;
for(int i = 2; i < macAddStr.Length; i=i+2)
macAddStrNew = macAddStrNew.Insert(i+insertedCount++, ":");
Related
We have a requirement to get the printer IP Address configured in the default printer driver in Control Panel in our UWP app.
I was able to retrieve the "System.DeviceInterface.PrinterPortName" by fetching interface class GUID and passing this above property for retrieval.
But I couldn't get "System.Devices.IpAddress" similarly.
Code pasted below for PortName.
I badly need the IP address as the port name is user's choice and could be modified to any name removing the IP address.
Kindly help sharing working code to retrieve the IP Address using above property or any other way in UWP app.
Below is Working Code for Port Name, Kindly help to fetch IP Address of the same port similarly.
string aqsFilter = "System.Devices.InterfaceClassGuid:=\"{0ecef634-6ef0-472a-8085-5ad023ecbccd}\"";
string[] propertiesToRetrieve = new string[] { "System.DeviceInterface.PrinterPortName"};
DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(aqsFilter, propertiesToRetrieve);
foreach (DeviceInformation deviceInfo in deviceInfoCollection)
{
if (deviceInfo.IsDefault == true)
{
string strPortName = (string)deviceInfo.Properties["System.DeviceInterface.PrinterPortName"];
if (!string.IsNullOrEmpty(strPortName))
{
strPortName = await ParsePortName(strPortName);
if (!string.IsNullOrEmpty(strPortName))
{
_strIPAddress = strPortName;
}
}
break;
}
}
This is not endorsed because the IP address can change and so it is unreliable.
That being said, if your printer is installed using wsd, it is technically supported
E.g.,
DEVPKEY_PNPX_IpAddress DEVPROP_TYPE_STRING_LIST 32 "10.137.192.202"
But there is no way to reliably use this without a lot of various scenario checks since the IP address may change.
Furthermore, looking at this example, you are not hitting the DAF providers but looking for devices. You are using 0ecef634-6ef0-472a-8085-5ad023ecbccd which is the printer class guid. It also does not look like IP address is propagated in the PnP Explorer property bag so the IP address is not accessible.
My main goal is to to get VIN no of my control unit but for that i need to send command to controller and before sending any command to controller i must have to claim address.
I have send below command on my network but didn't got any response from it.
Msg.id.pdu_bit.edp = 0;
Msg.id.pdu_bit.dp = 0;
Msg.id.pdu_bit.pf = 234;
Msg.id.pdu_bit.ps = 255;
Msg.id.pdu_bit.sa = 249;
Msg.id.pdu_bit.pri = 6;
Msg.buf[0] = 0x00; //LSB First
Msg.buf[1] = 0xEE; // pgn for claim address
Msg.buf[2] = 0x00;
Msg.len = 3;
Is this is right way to claim address or do i have send different command??
It looks like you have some confusion between PGN 60928 (address claim) and PGN 59904 (request PGN)
Msg.id.pdu_bit.pf = 234;
Needs to be
Msg.id.pdu_bit.pf = 238;
The PGN for address claim is 60928 so your PF field in your J1939 header needs to be 238 (0xEE). Your data is going to be application specific although it's data length should be 8. See J1939 Spec slide 41 for more information on this data format.
Alternatively if you use PGN 59904, THAT is when your data length is 3 (unless you have more application specific information) and your data is the PGN that you want to request.
You do not have to request an address claim PGN, you just simply send out the address claim with your source address set to the address you want to claim.
I'm trying to make a program that sends SNMP queries to some switches in the network.
Using the Net-snmp tools, I can send get requests to the switch using its name, and it works fine. But SNMP4J requires an IP address in CommunityTarget, so I get an IllegalArgumentException.
This is the relevant part of the code:
TransportMapping transport = new DefaultUdpTransportMapping();
transport.listen();
CommunityTarget comtarget = new CommunityTarget();
comtarget.setCommunity(new OctetString("public"));
comtarget.setVersion(SnmpConstants.version1);
comtarget.setAddress(new UdpAddress("switchName")); // exception happens here
comtarget.setRetries(2);
comtarget.setTimeout(1000);
How can I work around this?
You can get the IP address by using DNS resolution, like this answer says:
InetAddress address = InetAddress.getByName(switchName);
System.out.println(address.getHostAddress());
I actually tried with the following code, which gave me a result of the local machine Ip address, name and the server Ip address
var hostNamesList = NetworkInformation.GetHostNames();
HostName serverHost = new HostName("cptdomain.ctl.local");
StreamSocket clientSocket = new Windows.Networking.Sockets.StreamSocket();
// Try to connect to the remote host
await clientSocket.ConnectAsync(serverHost, "http");
foreach (var entry in hostNamesList)
{
if (entry.Type == HostNameType.DomainName)
{
hostName.Text = "Machine Name : " + entry.DisplayName;
IPAddress.Text = "Machine IP : " + clientSocket.Information.LocalAddress.DisplayName;
ServerAddress.Text = "Server IP : " + clientSocket.Information.RemoteAddress.DisplayName;
}
}
}
But actually my requirement is, how to get the list of IP addresses and name of the computers that are connected to the server in LAN for Windows Store Apps.
Please guide me in this to get the proper solution for running my store app.
Note: Here I was working with windows8 store apps with WinRT
This is how you do it in a full fat c# application, but I don't think you can do this on a winrt application. At a minimum you will have to add the private network privilege.
I'm trying to my application to retrieve the IP address when it's connected to the Wifi network but I'm not too sure how to get that done.
I've looked at RadioInfo and there's a function getIPAddress(int apnId). Is this the right one?
I've also looked at WLANInfo but that one doesn't seem to have any IP related functions.
Anyone can help me with this?
klyubin wrote:
[...] the best solution (as it relies on documented behavior) is to open a udp socket (or TCP server socket) over WiFi and query its IP address. Another hack is to get the APN ID for the "MagicRudyAPN.rim" using getAccessPointNumber, and then query its IP address using getIPAddress. MagicRudyAPN.rim seems to be a virtual/fake APN for accessing/addressing the IP tunnel to the WiFi network.
int apnId = RadioInfo.getAccessPointNumber("MagicRudyAPN.rim");
byte[] ipByte = RadioInfo.getIPAddress(apnId);
String ip = "";
for (int i = 0; i < ipByte.length; i++) {
int temp = (ipByte[i] & 0xff);
if (i < 3)
ip = ip.concat("" + temp + ".");
else {
ip = ip.concat("" + temp);
}
}