C# Getting a lot of 0 ms reply while ping an IP address [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 months ago.
Improve this question
I have a bunch of ip address and trying to get reply with PingReply class but it's returns a lot of 0 ms while the ip address is live and reachable, why?
Ping srvPing = new Ping();
PingReply reply = srvPing.Send("195.228.152.149", 1000); // example ip which returns 0 ms
String ping = reply.RoundtripTime.ToString();
Debug.WriteLine(ping + "ms");
//output: 0ms

Please check the Status property from your reply variable. If the value of Status is not Success, you should not use the values returned by the RoundtripTime. The RoundtripTime property will return zero in that case.

Related

NotSupportedException: Cannot serialize interface C# Web Service [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 days ago.
Improve this question
I'm using for the first time Web Services, and when I try to consume it, I have this error:
NotSupportedException: Cannot serialize interface
I tried changing the configuration names or adding [XmlSerialize] but is not working...
What should I do to avoid this?
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportCredentialOnly);
EndpointAddress endpoint =
new EndpointAddress("myendpoint")
client.ClientCredentials.UserName.UserName = _userName;
client.ClientCredentials.UserName.Password = _password;
SoapClient client = new SoapClient(binding, endpoint);
using (new OperationContextScope(client.InnerChannel)) --> here I have the problem
{
//My code
}

Why does creating contact forms require a password? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
So Im looking at having a contact form on my website where a person can type a message and send it, with the mesage going to my inbox.
But every time I see them online Ill see this:
System.Net.NetworkCredential("yourEmail#gmail.com", "YourPassword");
Why do I need to provide my password? When you send someone a regular email, you dont need THEIR password.
I also have security concerns. Ok, it's in a .cs file, but still, I dont like seeing my password in plain text there.
Also, what about if its for a big company? Does ebay have their password in plain text? It's something I doubt. How do other people do it?
You absolutely don't want the users password.
But for your contact form to be able to send a mail it needs to be send by a valid email client. Say for example you want to use the gmail server for your mail, you need to provide your credentials for it.
As for the second part of your question, please don't store these plain text in code. You can easily acces those from app.config / web.config
(for example see: Embed credentials for webclient in C# Console Application app.config?)
This is because you have your own SMTP relay and your own credentials.
So when setting up the mailer on your side, you need to specify a reply to email address.
Below is a working example of how do it
var m = new MailMessage { Subject = txtSubject.Text, IsBodyHtml = true, Body = emailOpeningLine + txtMessage.Text };
try
{
m.To.Add(new MailAddress("to");
m.From = new MailAddress("senders email address");
m.ReplyToList.Add("senders email address");
foreach (var attachment in Attactments)
{
m.Attachments.Add(new Attachment(attachment));
}
client.Send(m);
m.To.Clear();
m.Attachments.Clear();
}
catch (SmtpException esException)
{
}
catch (Exception ex)
{
}
Re your other questions, you can keep the passwords in a database, but remember to encrypt them.

C# asp.net Get Ipv4 ip address of a client [duplicate]

This question already has answers here:
How to get a user's client IP address in ASP.NET?
(21 answers)
Closed 7 years ago.
My below code is getting ivp6 ip address am not sure how to get ipv4 in the same manner.
string ipAddress = "";
if (Dns.GetHostAddresses(Dns.GetHostName()).Length > 0)
{
ipAddress = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
}
This code:
Dns.GetHostAddresses(Dns.GetHostName())
Will return an array of all IP addresses assigned to the local machine. When you assign to the ipAddress variable, you are using "[0]", which only takes the first IP address in the list.
Look at the entire array and you might find that you are indeed getting the IPv4 addresses too.

Connect to Stack Overflow API [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to connect to the Stack Overflow API as one of my first api calls, but I am struggling.
Can someone tell me why this code does not return a success code?
using (var handler = new HttpClientHandler())
using (var client = new HttpClient(handler))
{
client.BaseAddress = new Uri("https://api.stackexchange.com/");
var response = await client.GetAsync("questions");
if (response.IsSuccessStatusCode)
{
}
else
{
Console.WriteLine(response.ToString());
}
}
The response tells you site is required. Hit https://api.stackexchange.com/questions?site=stackoverflow instead.
You're getting back
{"error_id":400,"error_message":"site is required","error_name":"bad_parameter"}
If you read the error and documentation, it needs to know which StackExchange site you want. Try:
https://api.stackexchange.com/questions?site=stackoverflow

how to use mailing system in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
i want to have an email system , when user done an action after that someone recieve an email in C#
so now how I can do that ??
You could use the .Net SmtpClient class as follows:
using System.Net.Mail;
// the e-mail details
String from = "me#server.com";
String to = "someone#server.com";;
// build up the message
MailMessage message = new MailMessage(from, to);
message.Subject = "My Title";
message.Body += "This is the biody of my message";
// create a server pointing to your mail server
String server = "mail.server.com";
// create a client
SmtpClient client = new SmtpClient(server);
client.Credentials = CredentialCache.DefaultNetworkCredentials;
// send the message
client.Send(message);
To send an email in .NET you could use the SmptClient class.

Categories

Resources