I have an application I have been working on and it can be slow to start when my ISP is down because of DNS. My ISP was down for 3 hours yesterday, so I didn't think much about this piece of code I had added, until I found that it is always slow to start. This code is supposed to return your IP address and my reading of the link suggests that should be immediate, but it isn't, at least on my machine.
Oh, and yesterday before the internet went down, I upgraded (oymoron) to XP SP3, and have had other problems.
So my questions / request:
Am I doing this right?
If you run this on your machine does it take 39 seconds to return your IP address? It does on mine.
One other note, I did a packet capture and the first request did NOT go on the wire, but the second did, and was answered quickly. So the question is what happened in XP SP3 that I am missing, besides a brain.
One last note. If I resolve a FQDN all is well.
Public Class Form1
'http://msdn.microsoft.com/en-us/library/system.net.dns.gethostaddresses.aspx
'
'excerpt
'The GetHostAddresses method queries a DNS server
'for the IP addresses associated with a host name.
'
'If hostNameOrAddress is an IP address, this address
'is returned without querying the DNS server.
'
'When an empty string is passed as the host name,
'this method returns the IPv4 addresses of the local host
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim stpw As New Stopwatch
stpw.Reset()
stpw.Start()
'originally Dns.GetHostEntry, but slow also
Dim myIPs() As System.Net.IPAddress = System.Net.Dns.GetHostAddresses("")
stpw.Stop()
Debug.WriteLine("'" & stpw.Elapsed.TotalSeconds)
If myIPs.Length > 0 Then Debug.WriteLine("'" & myIPs(0).ToString)
'debug
'39.8990525
'192.168.1.2
stpw.Reset()
stpw.Start()
'originally Dns.GetHostEntry, but slow also
myIPs = System.Net.Dns.GetHostAddresses("www.vbforums.com")
stpw.Stop()
Debug.WriteLine("'" & stpw.Elapsed.TotalSeconds)
If myIPs.Length > 0 Then Debug.WriteLine("'" & myIPs(0).ToString)
'debug
'0.042212
'63.236.73.220
End Sub
End Class
See post #7 here Fix
A little power shell testing: Comments marked *
*returns in < 1 sec.
PS C:\Documents and Settings\MyPC> [System.Net.Dns]::GetHostAddresses("www.msn.com")
IPAddressToString : 65.55.17.27
Address : 454113089
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
IPAddressToString : 65.55.17.26
Address : 437335873
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
*takes about 40 seconds
PS C:\Documents and Settings\MyPC> [System.Net.Dns]::GetHostAddresses("")
IPAddressToString : 192.168.1.2
Address : 33663168
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
*returns in < 1 sec.
PS C:\Documents and Settings\MyPC> [System.Net.Dns]::GetHostAddresses("192.168.1.2")
IPAddressToString : 192.168.1.2
Address : 33663168
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
*takes about 40 seconds
PS C:\Documents and Settings\MyPC> [System.Net.Dns]::GetHostAddresses("")
IPAddressToString : 192.168.1.2
Address : 33663168
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
*i thought this should return several addresses
PS C:\Documents and Settings\MyPC> [System.Net.Dns]::GetHostAddresses("localhost")
IPAddressToString : 127.0.0.1
Address : 16777343
AddressFamily : InterNetwork
ScopeId :
IsIPv6Multicast : False
IsIPv6LinkLocal : False
IsIPv6SiteLocal : False
PS C:\Documents and Settings\MyPC>
Related
I was trying to read the BeginX, BeginY, EndX and EndY cells from all the connect object in a page, so that I could record which point from a shape is connected to which connect.
what confuses me is that the CellsU and CellsSRC seems to be not working with connect object, even it is suggested in office docs for like EndX cell. What shall I use if I want to read and save some cells from a connect object then?
You might find what you're looking for if you explore the objects returned from the connects() method on the connect object. Each object represents the connections made on each end of the connector and can lead you to the data in the shape object that has the coordinate information.
$c.Connects()
Application : Microsoft.Office.Interop.Visio.ApplicationClass
Stat : 0
FromSheet : System.__ComObject
ToSheet : System.__ComObject
FromCell : System.__ComObject
ToCell : System.__ComObject
FromPart : 9
ToPart : 3
ObjectType : 8
Index16 : 1
Document : System.__ComObject
Index : 1
ContainingPageID : 0
ContainingMasterID : -1
Application : Microsoft.Office.Interop.Visio.ApplicationClass
Stat : 0
FromSheet : System.__ComObject
ToSheet : System.__ComObject
FromCell : System.__ComObject
ToCell : System.__ComObject
FromPart : 12
ToPart : 3
ObjectType : 8
Index16 : 2
Document : System.__ComObject
Index : 2
ContainingPageID : 0
ContainingMasterID : -1
In CATIAV5 R26, I'm trying to dump the CATSettings related to the General --> Document tab to catvbs.
Consider that this should be a first step towards my final objective: fully automate settings with macros, as it is suggested in the official docs (http://www.maruf.ca/files/caadoc/CAAScdInfTechArticles/CAAInfSettings.htm)
I expect the dump function to create a catvbs containing ALL the settings of this tab, but instead, ONLY the DLName settings are written: the result is a General-Document.catvbs containing only the settings from CATSysDLNameSettingCtrl
The majority of settings, for example those inside the "Document Environment" or "Linked Documents Localization" sections (see image below) are not exported.
Is this inteded? Is this a bug? How can I be sure to have ALL settings exported to catvbs?
CATSettings Tab
Dumped General-Document.catvbs
Language="VBSCRIPT"
Sub CATMain()
Set settingControllers1 = CATIA.SettingControllers
Set dLNameSettingAtt1 = settingControllers1.Item("CATSysDLNameSettingCtrl")
Dim boolean1
boolean1 = dLNameSettingAtt1.DLNameCreationRight
'--------------------------------------------------
' Returned value : (Boolean) True
'--------------------------------------------------
Dim bSTR1
bSTR1 = ""
Dim bSTR2
bSTR2 = ""
Dim boolean2
boolean2 = dLNameSettingAtt1.GetDLNameCreationRightInfo(bSTR1, bSTR2)
'--------------------------------------------------
' Parameter 1 : (String) "Set at Admin Level 1"
' Parameter 2 : (String) "Locked at Admin Level 1"
' Returned value : (Boolean) False
'--------------------------------------------------
Dim boolean3
boolean3 = dLNameSettingAtt1.RootDLNameCreationRight
'--------------------------------------------------
' Returned value : (Boolean) True
'--------------------------------------------------
Dim bSTR3
bSTR3 = ""
Dim bSTR4
bSTR4 = ""
Dim boolean4
boolean4 = dLNameSettingAtt1.GetRootDLNameCreationRightInfo(bSTR3, bSTR4)
'--------------------------------------------------
' Parameter 1 : (String) "Default value"
' Parameter 2 : (String) "Unlocked"
' Returned value : (Boolean) False
'--------------------------------------------------
Dim arrayOfVariantOfBSTR1
arrayOfVariantOfBSTR1 = dLNameSettingAtt1.GetDLNameList()
'--------------------------------------------------
' Returned value : (Array)
' Array[0] : (Variant) (String) "My Sample DL Name"
'--------------------------------------------------
Dim bSTR5
bSTR5 = ""
Dim bSTR6
bSTR6 = ""
Dim bSTR7
bSTR7 = ""
dLNameSettingAtt1.GetDLName "My Sample DL Name", bSTR5, bSTR6, bSTR7
'--------------------------------------------------
' Parameter 1 : (String) "My Sample DL Name"
' Parameter 2 : (String) "/tmp/here"
' Parameter 3 : (String) "${MY_SAMPLE_VAR}"
' Parameter 4 : (String) ""
'--------------------------------------------------
Dim bSTR8
bSTR8 = ""
Dim bSTR9
bSTR9 = ""
Dim boolean5
boolean5 = dLNameSettingAtt1.GetDLNameInfo("My Sample DL Name", bSTR8, bSTR9)
'--------------------------------------------------
' Parameter 1 : (String) "My Sample DL Name"
' Parameter 2 : (String) "Set at Admin Level 1"
' Parameter 3 : (String) "Unlocked"
' Returned value : (Boolean) False
'--------------------------------------------------
End Sub
My mistake, I misunderstood your question. I would delete myself this answer but I it seems I cannot do it.
For your case it seems only DLNames is allowed and I suppose you will get only that catvbs.
If you want all catvbs for all catsettings then you need to do what is in picture bellow (see red arrow).
I'm afraid that not all the CATSettings are exposed to automation (as gdir correctly pointed out), including those I'm looking for.
as you can see in the documentation (emphasis mine)
In addition to using the Tools->Options... command, many settings can
be managed and administrated using Automation ...
many, not all.
This sadly prevents the full automation of CATSettings, as far as I know.
I have to create a really simple application in vb. My app contains a button and a listview. In my application i have to run threads, and insert in a listview the name and time of the thread executed. My code starts when i click on the threading button
my code is the following
Private Sub btnThreading_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThreading.Click
Try
For index = 0 To 3
Dim th As New Threading(index)
Me.Invoke(New DoStuffDelegate(AddressOf th.Run))
Next
lstText.View = View.Details
lstText.Columns.Add("Thread Name")
lstText.Columns.Add("Time")
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
And the page threading is the following
Public Class Threading
Private threadName As String
Dim value As Date
Private Delegate Sub DoStuffDelegate()
Dim lockthis As New Object
Sub New(ByVal ThreadName As String)
Me.threadName = "Thread Number : " & ThreadName
End Sub
Public Sub Run()
For index = 0 To 3
Thread.Sleep(1000)
value = Date.Now
Console.WriteLine(threadName & " Time : " & value)
Dim item3 As New ListViewItem(Me.threadName)
item3.SubItems.Add(Me.value)
Form1.lstText.Items.AddRange(New ListViewItem() {item3})
Next
End Sub
End Class
if I use a thread without the delegate like the following
Dim th As New Threading(index)
Dim trd = New Thread(AddressOf th.Run)
trd.start()
, my output window shows the names and threads as it should for example
Thread Number : 1 Time : 9/15/2014 9:51:00
Thread Number : 0 Time : 9/15/2014 9:51:00
Thread Number : 2 Time : 9/15/2014 9:51:00
Thread Number : 3 Time : 9/15/2014 9:51:00
but doesn't show anything in the list view. but if i choose to use the delegate like the following,
Dim th As New Threading(index)
Me.Invoke(New DoStuffDelegate(AddressOf th.Run))
it shows the following in the output
Thread Number : 1 Time : 9/15/2014 9:50:59
Thread Number : 0 Time : 9/15/2014 9:51:00
Thread Number : 2 Time : 9/15/2014 9:51:01
Thread Number : 3 Time : 9/15/2014 9:51:02
and it shows it in the listview.So it works but doesn't execute the code as a thread does. But finally when I use the following code
Dim th As New Threading(index)
Dim trd = New Thread(AddressOf th.Run)
Me.Invoke(New DoStuffDelegate(AddressOf trd.Start))
, my output window shows the names and threads as it should for example
Thread Number : 1 Time : 9/15/2014 9:51:00
Thread Number : 0 Time : 9/15/2014 9:51:00
Thread Number : 2 Time : 9/15/2014 9:51:00
Thread Number : 3 Time : 9/15/2014 9:51:00
but doesn't show anything in the list view.
I want the list view to show this
Thread Number : 1 Time : 9/15/2014 9:51:00
Thread Number : 0 Time : 9/15/2014 9:51:00
Thread Number : 2 Time : 9/15/2014 9:51:00
Thread Number : 3 Time : 9/15/2014 9:51:00
All threads should have the same time, all threads should start at the same time,and they should appear in my list view.
Please help, I've been working on this for like two weeks and I'm not finding any solution!
What are you adding to the ListView? The name and the time, right? So, when you invoke a method on the UI thread, pas the name AND the time. Don't wait until you're on the UI thread to get the time because obviously that's going to be later.
I m trying to understand and modifying a network discovery program..if somebody help me understand the following code i'd be obliged
Dim DomainEntry As New DirectoryEntry("WinNT://" & workGroup.Trim())
DomainEntry.Children.SchemaFilter.Add("computer")
X = 5 : Y = 5 : Count = 1
For Each Machine As DirectoryEntry In DomainEntry.Children
Dim CompNode As New TreeNode(), CompInfo(1) As String
CompInfo(0) = Machine.Name
Dim Tempaddr As System.Net.IPHostEntry = Nothing
Try
Tempaddr = DirectCast(Dns.GetHostByName(Machine.Name), System.Net.IPHostEntry)
Dim TempAd As System.Net.IPAddress() = Tempaddr.AddressList, str As String = ""
For Each TempA As IPAddress In TempAd
CompInfo(1) = TempA.ToString()
Next
Catch ex As Exception
CompInfo(1) = ""
End Try
Hopefully this helps:
''//The variable "workGroup" holds your Active Directory domain name
''//The "DomainEntry" variable will represent the root of your Active Directory hierarchy
Dim DomainEntry As New DirectoryEntry("WinNT://" & workGroup.Trim())
''//Tell the "DomainEntry" variable to only look at "computer" objects
DomainEntry.Children.SchemaFilter.Add("computer")
''//These variables are not used
X = 5 : Y = 5 : Count = 1
''//Loop through all of the computers in the domain
For Each Machine As DirectoryEntry In DomainEntry.Children
''//First variable is not used, second is an array with two parts
Dim CompNode As New TreeNode(), CompInfo(1) As String
''//Set the first part of the array to the machine name
CompInfo(0) = Machine.Name
''//The next block tries to get the machine IP by looking it up in DNS. It can fail at several points so it gets wrapped in a try/catch just in case
Dim Tempaddr As System.Net.IPHostEntry = Nothing
Try
''//Try getting the machine IP
Tempaddr = DirectCast(Dns.GetHostByName(Machine.Name), System.Net.IPHostEntry)
''//A machine can have several IP addresses so this gets a full list of them
Dim TempAd As System.Net.IPAddress() = Tempaddr.AddressList, str As String = ""
''//Most machines will probably have just one IP address, but just in case this code takes the last one that it finds
For Each TempA As IPAddress In TempAd
''//Set the second part of our array to the IP address
CompInfo(1) = TempA.ToString()
Next
Catch ex As Exception
''//If this is hit then there was a problem getting the IP address so set it to blank
CompInfo(1) = ""
End Try
Next
This is a program for reading a local Active Directory. "WinNT://workgroup" is the address of the directory.
The next line
DomainEntry.Children.SchemaFilter.Add("computer")
Indicates that you're only interested in items of type "computer". From there on, you're creating a two dimensional array which represents the computers with the machine name in the zeroth element, and the IP address of the machine in the second. If there is more than one IP entry for the machine, the array will contain the last one.
I am trying to get country location from the ip address which I am also looking up from actual url. However for certain urls I am getting the following error:
The requested name is valid and was found in the database, but it does not have the correct associated data being resolved for
I wanted to use the following code to identify the proxy perhaps but since this is a regular console app I am not sure how to get around it. Here is my code;
For Each prod In querylist
If myfetcher.getHtml(prod, userAgent, page) Then
' The lines below I use to find proxy ip
' but error name 'Request' not declared
' Dim nowip As String
' nowip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
' If nowip = "" Then
'nowip = Request.ServerVariables("REMOTE_ADDR")
'End If
'
If prod.Contains("http://") Then
prod = Regex.Replace(prod, "http://", "")
End If
badHost = prod
Dim ipEntry As IPHostEntry = Dns.GetHostByName(prod)
Dim IPAdd As IPAddress() = ipEntry.AddressList
Dim i As Integer = 0
For i = 0 To IPAdd.GetUpperBound(0)
number = number & "IP Address {0}:{1}" & IPAdd(i).ToString
Next
IPList.Add(prod & " " & number)
number = ""
Else
badList.Add(prod)
number = ""
End If
count = count + 1
Next
Here's a language agnostic way to do it:
do a HTTP GET for
domain2ip.net/:url
like
http://domain2ip.net/www.edresearch.co.jp
is
122.200.237.66
you can even to it from JavaScript
$.getJSON("http://domain2ip.net/google.com", callback);
Disclosure: it's my site, and open source.